go to previous page   go to home page   go to next page
Integer five = 5 ;
Integer ten = 10 ;

Answer:

five.compareTo( ten ) is negative.

The declaration of the two Integer variables looks wrong, but they are actually correct. Autoboxing automatically constructs Integer objects for the two primitive integers.


Natural Order

Line of Objects in Order

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

objectA.compareTo(objectB)

is negative. For example, X.compareTo("orange") is negative for all the fruit X left of "orange".


QUESTION 5:

What is "grape".compareTo( "banana" );


go to previous page   go to home page   go to next page