Computer Science, asked by parthu689, 1 year ago

What will happen if two different hashmap key objects have the same hashcode?

Answers

Answered by clue
0

They will just be added to the same bucket and equals() will be used to distinguish them. Each bucket can contain a list of objects with the same hash code.

In theory you can return the same integer as a hash code for any object of given class, but that would mean that you loose all performance benefits of the hash map and, in effect, will store objects in a list.

Similar questions