Pergunta de entrevista da empresa Goldman Sachs

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

Respostas da entrevista

Sigiloso

18 de jul. de 2011

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

Sigiloso

20 de ago. de 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.