There is no check for equality of values, only for key equality. The object will be replaced equal if the key you specified matches the key that is already on the map.
If the value was previously associated with the key, this value will be returned by the put method. Here is a snippet from the HashMap<K,V> source:
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))) { V oldValue = e.value; e.value = value; e.recordAccess(this); return oldValue; } }
source share