Java HashMap: how it identify a key

Key object's equals() and hashCode() are used to identify the key in the HashMap. In other words, you may need to override equals() and hashCode() methods of the key class.

Note: TreeMap is a sorted map, so you need to let the Key class implements Comparable interface, implements compareTo() method.

See also this discussion.

No comments:

Post a Comment