Objects that have an ordering are compared using the compareTo() method.
5. Natural Order
five.compareTo( ten )is negative.
The declaration of the two
Integervariables looks wrong, but they are actually correct.
Autoboxing automatically constructs
Integerobjects for the two primitive integers.
Objects that implement
compareTo() can be arranged into a natural order. This order can be visualized as an arrangement of objects from left to right as on a number line.
The strings in the picture are arranged left to right in dictionary order.
If an object A is left of another object B, then
is negative. For example,
X.compareTo("orange") is negative for all the fruit X left of "orange".
What is "grape".compareTo( "banana" );