posted 12 years ago
Implementing Comparable lets object compare itself to other objects of the same class, it provides natural ordering fo objects. If you implement Comparator you create small class which you can use to compare objects of other classes, you are injecting ability to order from outside.
Comparable provides just one compareTo() method which means that you will have only one way of comparing objects. In most cases its enough, but sometimes you will want to compare objects of your class in many ways (for example: 'normal' way of comparing Person objects could use names, but in specific case you could need comparing by age or by height) - in such cases Comparator is better, you can have separate class for each criteria.
Sometimes you have to compare objects of class which doesn't implement Comparable and cannot be chanched - in such cases the only way is using Comparator.
To sum up: Use Comparable in simple cases where you can control comparable class. If you cannot modify class or you need more than one way of comparing - use Comparator.