Home Cheat Sheets How HashMap Works Internally
📋 CHEAT SHEET

How HashMap Works Internally

Illustrated diagram of Java HashMap internals — hashing, bucket array, collision handling with linked list and TreeNode.

Read Full Tutorial →
How HashMap Works Internally
Step 1 — Key → hashCode() → bucket index
"name"
hashCode()
3373752
% 16
index = hash & (n-1)
bucket 8
"age"
hashCode()
96891
% 16
index = hash & (n-1)
bucket 3
"city"
hashCode()
3053228
% 16
index = hash & (n-1)
bucket 8 collision!
Step 2 — Bucket array (Node[] table, capacity = 16)
0
null
1
null
2
null
3
"age" → 25
4
null
5
null
6
null
7
null
8
"name" → "Alice"
↳ "city" → "Paris" (linked list)
9
null
10
null
·
···
15
null
Key facts
Default capacity
16
Load factor 0.75 → resize at 12 entries
Collision
LinkedList
→ TreeNode (Red-Black) at 8+ entries
Resize
×2
Doubles capacity, rehashes all keys
More Cheat Sheets
Java Collections Cheat SheetJava Streams API Cheat SheetPython Built-in Functions Cheat SheetSQL Joins Cheat SheetDocker Commands Cheat SheetJVM Memory Model DiagramMicroservices Architecture DiagramPandas Cheat Sheet