Table of contents
Why does Map exist?
What would life be without it?
HashMap: the street analogy
hashCode() and equals() explained
Collisions: when two people share a house
Load factor and resizing
The other Map types
The one rule you must never break
Interview problems where Map is the answer
SECTION 1.
Why does Map even exist?
Before touching any internals, let's nail the real problem Map was built to solve because if you understand the problem, everything else makes sense automatically.
Imagine you work at a hotel front desk. 1,000 guests are checked in. Your boss walks over and asks:
The scenario "Is John Smith in room 847?"
Enter fullscreen mode
Exit fullscreen mode
You have two choices for how to answer that.
The hook label is the key. The room key hanging on it is the value.…