I have a class which I want to set up as keys in HashMap. I already have implemented the compareTo method for that class. But still when I do:
map.put(new MyKey(d
You need to implement hashCode() and equals(). compareTo() is additionally required for sorted map/set.
hashCode()
equals()
compareTo()
See this question for details.
HashMap doesn't check compareTo();
HashMap
HashMap checks hashCode() and equals().