Why do all HashMap(s) return same hashCode
Because all three HashMaps hm1, hm2 and hm3 are equal using equals(); that's part of the contract of hashCode().
You can use maps as hash keys, but their concept of equals is not object identity (==). Rather, they are equal if and only if (roughly speaking) they have the same keys, and the keys map to the same values (where same is defined by equals() ). More precisely, see the API:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/AbstractMap.html#equals(java.lang.Object) http://java.sun.com/j2se/1.5.0/docs/api/java/util/AbstractMap.html#hashCode() You might want to try putting some different things into hm1, hm2 and hm3, so that they are no longer equal using equals(), and see how that affects your output.