equals
:
required for checking equality and restricting duplicates. Many classes of Java Library use this in case they wanted to find duplicates. e.g. HashSet.add(ob1)
will only add if that doesn't exist. So if you are extending some classes like this then override equals()
.
compareTo
:
required for ordering of element. Again for stable sorting you require equality, so there is a return 0.