This means that two elements with different keys that have the same hash code fall into the same bucket .
In your case, the two keys are the same, so the second position overwrites the first.
But assuming you have your own class
class Thingy { private final String name; public Thingy(String name) { this.name = name; } public boolean equals(Object o) { ... } public int hashcode() {
And created several instances. i.e.
Thingy a = new Thingy("a"); Thingy b = new Thingy("b"); Thingy c = new Thingy("c");
And inserted them into the card. Then one bucket, that is, a bucket containing material with a hash code of 1, will contain a list (chain) of three elements.
Map<Thingy, Thingy> map = new HashMap<Thingy, Thingy>(); map.put(a, a); map.put(b, b); map.put(c, c);
Thus, retrieving an item using any Thingy key will search for the hash code O (1), followed by a linear search for O (n) in the list of items in the bucket with hash code 1.
Also, be careful to make sure that you respect the correct relationship when implementing hashcode and equals. Namely, if two objects are equal, then they must have the same hascode, but not necessarily otherwise, since several keys can receive the same hash code.
Oh, and for complete definitions of open hashing and closed hash tables, see here http://www.c2.com/cgi/wiki?HashTable