1.

How Does Get() Method Of Hashmap Works, If Two Keys Have The Same Hashcode?

Answer»

This is the follow-up of previous interview questions on equals and hashcode, in fact, SOMETIMES this leads to a discussion of the EARLIER point. When two key return same hashcode, they END up in the same bucket. Now, in ORDER to find the CORRECT value, you used keys.equals() method to compare with key stored in each Entry of linked list there. Remember to point out keys.equals() method, because that's what interviewer is looking for.

This is the follow-up of previous interview questions on equals and hashcode, in fact, sometimes this leads to a discussion of the earlier point. When two key return same hashcode, they end up in the same bucket. Now, in order to find the correct value, you used keys.equals() method to compare with key stored in each Entry of linked list there. Remember to point out keys.equals() method, because that's what interviewer is looking for.



Discussion

No Comment Found