String Methods

AP Computer Science A· difficulty 4/5

String a = "apple";
String b = "banana";
System.out.println(a.compareTo(b) < 0);

What is printed?

  • A

    0

  • B

    -1

  • C

    false

  • D

    true

    check_circle

Explanation

"apple" comes before "banana" lexicographically, so compareTo returns a negative integer, which is less than 0.

Want 10 more like this — adaptive to your weak spots?

Related questions