hi,
I was just (5 minutes ago) studying this
It goes like this: If you are designing your OWN classes and there is a need for comparing, you might prefer to use the
natural comparison method by implementing Comparable
here is code I just had to copy from my editor
Getal = dutch for Number (I couldn't use Number as classname could I
)
But what if you get a class that you don't have the source code of and you need to sort the items ? Or what if the class has allready implemented Comparable, but you want to sort the class on another value ?
then you might choose for the Comparator method! You just create a new Class and implement the compare() method; Usually the equals method inherited from Object or whatever is just fine
here is an example
The
AlphabeticComparator class does actually the same as the
public static final Comparator CASE_INSENSITIVE_ORDER from String
Thanks for pointing that out John!! I didn't knew it had that field
anyway, karthik hope I could help you
Dave
[This message has been edited by Dave Van Even (edited October 14, 2001).]
[This message has been edited by Dave Van Even (edited October 14, 2001).]