Excellent question, Pandian! The Comparator.compare(Object, Object) and Comparator.equals(Object) methods are extremely different. Comparator.compare(Object, Object) specifies the meat of the Comparator interface: it determines if the first parameter is less than, equal to, or greater to the second. Comparator.equals(Object) instead compares a different Comparator
to the current one.
By default, an Object implementing the Comparator interface will inherit the equals(Object) method from its base class, Object. Object.equals(Object) returns true if the current object occupies the same memory space as the passed object. Basically, it only returns true if itself is passed to it.
The Comparator interface essentially maps out an option for equals(Object) to additionally return true if the passed Comparator has the same Comparator.compare(Object, Object). That is, they'll both sort a List in exactly the same way. The interface specifies this option to allow applications especially interested in performance a way to cache Comparators so they need not be created for each use.
As a beginner, you shouldn't worry about overriding equals(Object). Even as an advanced Java developer, you will likely only need to implement compare(Object, Object), as this is what Collections.sort(List) and other collections methods care about.
More information: http://java.sun.com/j2se/1.4.2/docs/...omparator.html
Adobe Systems, Inc.