Java: what makes two keys equal in a hashmap?

You need to override two methods in key class:
public int hashCode();
public boolean equals(Object o);

1 comment:

  1. Nice article but I believe its important to understand the consequences of not following this contract as well and for that its important to understand application of hashcode in collection classes e.g. How HashMap works in Java and how hashcode() of key is used to insert and retrieve object from hashMap.