, - .
Hashcode , hashCode().
, , - java.lang.Object . , . HashMap, HashSet .. , - ..
java.util.HashMap:
public V get(Object key) {
if (key == null)
return getForNullKey();
int hash = hash(key.hashCode());
for (Entry<K,V> e = table[indexFor(hash, table.length)];
e != null;
e = e.next) {
Object k;
if (e.hash == hash && ((k = e.key) == key || key.equals(k)))
return e.value;
}
return null;
}
As you can see, it was used to get the correct object from the data structure.
If you check the comment of the hash code of the object, it also clearly mentions this
* Returns a hash code value for the object. This method is
* supported for the benefit of hashtables such as those provided by
* <code>java.util.Hashtable</code>.
source
share