Java Zero to All All questionsPractise free
Interview questions › Java Foundations — Zero to Basics › Collections Deep Dive — List, Set, Map, Queue

What is the load factor, and what happens when a HashMap exceeds it?

Level II · JuniorCollections Deep Dive — List, Set, Map, Queue
Short answer

The load factor (default 0.75) is the fullness threshold: when the number of entries exceeds capacity * loadFactor, the HashMap resizes -- it doubles the bucket array and rehashes every entry into the new, larger array.

Explanation

Keeping the table under ~75% full keeps chains short so lookups stay near O(1). Resizing is expensive but happens rarely, so its cost is amortized across many inserts; 0.75 is the standard time/space compromise.

Common mistakes
  • Saying the load factor is the maximum number of entries.
  • Not knowing the default 0.75 and the resize to double capacity.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for Collections Deep Dive — List, Set, Map, Queue.

Practise free

More on Collections Deep Dive — List, Set, Map, Queue