If one is using the custom object as key then one needs to override equals() and hashCode() method, and one also need to fulfill the contract. If you want to store the custom object in the SortedCollections like SortedMap then one needs to make sure that equals() method is consistent to the compareTo() method. If inconsistent , then collection will not follow their contracts ,that is , Sets may allow duplicate elements.