Junior — Middle
In what case is rehashing of elements in HashMap initiated?
sobes.tech AI
Answer from AI
Rehashing of elements in a HashMap is triggered when the number of elements exceeds a certain threshold related to the current capacity and load factor. By default, if the number of elements becomes greater than capacity * loadFactor (usually loadFactor = 0.75), the HashMap increases the size of its internal array (usually doubling it) and redistributes all existing elements to new indices. This is necessary to maintain the efficiency of insert and search operations.