Internally HashMap has method hash() which defends against poorly written hash-code by applying special function. Next step is that returned value by hash() method is used to calculate index at which new Entry is stored inside backing array called table. It can happen that index is the same for two different keys. For that linked list is used but it is clear to me.
Why can index of backing table be the same for two different keys?
I know that hash-code can be poorly overriden but method hash() states that it protects from hash-code collisions. So why can index of backing table be the same?
EDIT Thanks to all for replies. @Dunkan Jones resize is done automatically when amount of elements you put into HashMap (size) is more or equal to threshhold(calculated according to initialCapacity and loadFactor provided in constructor). Look into method createEntry - size is incremented whenever new Entry is created. My question is why does hash() method + indexFor() method return together the same index for different objects. Due to this same index two Entries are put at the same bucket by means of linked list.
What causes hash() + indexFor() methods return the same index?
I think and can't realise what hash() and indexFor() do by those tricky >>> and & operators?
What hashing in HashMap means ?
Thanks again!