Multiple choice

String s1 = “abc”; String s2= “abg”; S1.compareTo(s2);

What will be result of the above code?

    • 4
  1. 4

    • 1
  2. 1

  3. 0

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

This is the correct answer. The first two characters from s1 and s2 (a vs a) are compared, they are equal. Then (b vs b) are compared they are also equal. Now ( c vs g ) are compared. Since c is 4 less than g, so -4 is returned. So this is correct answer.