## Comparable Interface

Objects that have an ordering are compared using the compareTo() method.

### 9. Nearly Same Strings, but Different Lengths

Answer:"bugbear".compareTo("bugbear")zero"bugbear".compareTo("Bugbear")NOT zero"Zorba".compareTo("Zorba!")NOT zero"mushroom".compareTo("mush room")NOT zero"TOAD".compareTo("TOAD")zero

# Nearly Same Strings, but Different Lengths

Rule 2: If string A is a prefix of string B, then A.compareTo(B) < 0.
If string B is a prefix of string A, then A.compareTo(B) > 0.

"bat".compareTo("batcave") < 0"apple".compareTo("applesauce") < 0"BAT".compareTo("BATCAVE") < 0"batcave".compareTo("bat") > 0"applesauce".compareTo("apples") > 0"BATCAVE".compareTo("BAT") > 0

In using this rule you need to pay attention to case. "BAT" is not a prefix of "batcave".

There are yet more rules.

Question 9:Decide on the value returned by compareTo():ComparisonZero, Negative, or Positive"bugbear".compareTo("bugbear")"bug".compareTo("bugbear")"pepper".compareTo("peppermint")"toadstool".compareTo("toad")"cat".compareTo("caterpillar")