Middle
What is the load factor in HashMap and what happens when it is reached?
sobes.tech AI
Answer from AI
The load factor in a HashMap is the fill coefficient that determines how full the table is. It is usually the ratio of the number of elements to the size of the bucket array.
When the number of elements reaches a point where the load factor multiplied by the array size exceeds a threshold (for example, 0.75 * capacity), the HashMap is resized (rehash): a new larger array is created, and all elements are redistributed across the new buckets.
This is necessary to maintain the efficiency of insert and search operations, as high fill levels increase collisions and degrade performance.