Comparator is used to set the order in elements in a TreeSet and a TreeMap. By using a comparator elements can be reordered. Method defined by comparator interface:
compare( ) method: It is used to compare two objects for ordering. It returns zero if both objects are equal, returns positive value if ob1 is greater than ob2, returns negative value if ob1 is less than ob2. If objects are not compatible for a comparison then ClassCastException is thrown.
int compare(Object ob1, Object ob2)
equals( ) method: It is used to check if an object is equal to the calling comparator. It returns true if ob and calling comparator uses the same ordering, otherwise it return false.
boolean equals(Object ob)