Both cases relate to hashCode()==0 , but equals differs, therefore, in two entries, and both get return related values.
Case with zero:
public V put(null,"abc") { if (key == null) return putForNullKey(value); } private V putForNullKey(V value) { .. addEntry(0, null, value, 0); ==> 0th index with 0 hashCode return null; }
Case with 0:
public V put(K key, V value) { int hash = hash(key.hashCode()); ==> 0 int i = indexFor(hash, table.length); ==> 0 for (Entry<K,V> e = table[i]; e != null; e = e.next) { Object k; if (e.hash == hash && ((k = e.key) == key || key.equals(k))) { ==> false .. } } modCount++; addEntry(hash, key, value, i); ==> addition to link list return null; }
source share