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?
They will just be added to the same bucket and equals()
will be used to distinguish them.
Each bucket can contain a list of objects with the same hash code.
In theory you can return the same integer as a hash code for any object of given class, but that would mean that you loose all performance benefits of the hash map and, in effect, will store objects in a list.