I gone through the Java's HashMap implementation methods put() and get(). I noticed that, when collision occurs, they compares hash of previous object with current one and also uses equals method for comparison. why is this necessary?. I feel comparing via equals method is enough. Please confirm if my assumption is correct. Please check below "else" part.
//Put method logic
if ((p = tab[i = (n - 1) & hash]) == null)
tab[i] = newNode(hash, key, value, null);
else {
Node<K,V> e; K k;
//talking about below logic
if (p.hash == hash &&
((k = p.key) == key || (key != null && key.equals(k))))
e = p;