created: 6/26/2006
A class implements the Comparable
interface when
its objects are expected to be arranged into a particular order.
For example, the class String
implements Comparable
,
because strings are often compared with each other and arranged into alphabetical order.
Numeric classes (such as Integer
or Double
) implement
Comparable
since number are often sorted into numeric order.
comparable()
method
This chapter describes the Java 5.0 version of Comparable
,
which uses generics.
Earlier versions of Java are somewhat different.
Arrange these strings into order: "orange", "apple", "plum".