posted 21 years ago
Let's say you have a class called Weight, and you want to compare objects of that class (e.g. for sorting).
You have two choices.
1. Weight can implement Comparable.
This means that the Weight class has some default ordering scheme that will be used by any code that cares about ordering (e.g. java.util collections).
2. Some class, not necessarily Weight, can implement Comparator.
This means that you may have many ways of ordering Weights. For example, you can have an IncreasingWeightOrder, DecreasingWeightOrder, etc. You pass objects that implement the interface in various ways to get the effect you want. If you don't pass one of those objects, then the comparator has no impact on anything.
Reid - SCJP2 (April 2002)