It is my understanding that two unequal objects can have the same hashcode. How would this be handled when adding or retrieving from a HashMap java?
In HashMap, keys along with their associative values are stored in a linked list node in the bucket and the keys are essentially compared in hashmap using equals() method not by hashcode.
hm.put("a","aValue"); // Suppose hashcode created for key "a" is 209
hm.put("b","bValue"); // Here hashcode created for key "b" is 209 as well.
a.equals(b) returns true, bValue will replace aValue and bValue will be returned.a.equals(b) returns false, another node will be created in the bucket list, so when you call get("b") you will get bValue since a.equals(b) is false.