Friday, May 29, 2009

Differences between the Comparable and Comparator interfaces

Comparable InterfaceComparator Interface
It uses the compareTo() method.

int objectOne.compareTo(objectTwo)
It uses the compare() method.

int compare(ObjOne, ObjTwo)
It is necessary to modify the class whose instance is going to be sorted.A separate class can be created in order to sort the instances.
Only one sort sequence can be created. Many sort sequences can be created.
It is frequently used by the API classes.It it used by third-party classes to sort instances.

No comments:

Post a Comment