Goldman Sachs interview question

HashMap - how will it store objects where hashcode is same? How will it retrieve them?

Interview Answers

Anonymous

18 Jul 2011

Basically if there is a hashcode collision then HashMap would rely on equals method for further equality checks.

Anonymous

20 Aug 2011

In case of key hashcode collision, the bucket will be same but considering each bucket location of hashmap as a linked list, the key-value pair will be stored on the next node in the same bucket. At the time of retreival, it will use keys.equal to get the correct node.