"apple", "orange", "plum".
This is the order that
compareTo() would place the strings.
An interface consists of constants and method declarations.
Comparable<T> interface consists of just one method (and no constants):
int compareTo( T obj )Compare the object running the method with
obj, which is of type T. Return a negative integer, zero, or a positive integer, when he object running the method is less than, equal, or greater than
T stands for the type of the objects.
If the objects are
Strings implement the
If an object is of a class that implements
then that object is less than, equal, or greater than
any object of that class.
returns an integer to show which of these three relations hold.
|Relation||objectA.compareTo( objectB )|
|objectA||Less Than||objectB||Negative Integer|
|objectA||Greater Than||objectB||Positive Integer|
compartTo() tell us enough?
If any two objects can be compared, and the result is less than, equal, or greater than is this enough to put a collection of objects in order?