Why does HashMap in java internally use array to store Entry Objects and not an ArrayList ?
1 Answer 1
The reason for this is highly likely that HashMap needs to control how its internal table is resized according to the number of entries and the given loadFactor.
Since ArrayList doesn't expose methods to resize its internal array to specific sizes (HashMap uses powers of 2 for its size to optimize rehashing, but ArrayList multiplies capacity by 1.5), it simply wasn't an option to be considered.
Also, even if ArrayList did increase capacity in the same way, relying on this internal detail would tie these two classes together, leaving no room to change the internal implementation of ArrayList at a later date as it could break HashMap or at the very least make it less memory efficient.