Multiple choice

The method s1.compareTo(s2) returns

  1. True if s1 < s2

  2. Negative if s1<s2, positive if s1>s2 and zero if s1=s2

  3. Zero if s1=s2

  4. Positive if s1 > s2

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The compareTo method in Java (for String) returns a negative integer if the calling string is lexicographically less than the argument, zero if they are equal, and a positive integer if it is greater.