According to this question
how-does-a-hashmap-work-in-java and this
Many Key-Values pairs could be stocked in the same bucket (after calculating the index of the bucket using the hash), and when we call get(key)
it looks over the linked list and tests using equals
method.
It doesn't sound really optimized to me, doesn't it compare hashCode
s of the linked List before the use of equals
?
If the answer is NO:
it means most of the time the bucket contains only 1 node, could you explain why ? because according to this logical explanation many differents keys could have the same bucket index.
how the implementation ensure the good distribution of keys ? this probably mean that the bucket table size is relative to the number of keys
And even if the Table Bucket size is equals to the number of keys, how the HashMap hashCode
function ensure the good distribution of keys ? isn't a random distribution ?,
could we have more details?