String Methods

AP Computer Science A· difficulty 3/5

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

What is printed?

  • A

    1

  • B

    -1

  • C

    5

  • D

    0

    check_circle

Explanation

compareTo returns 0 when both strings are lexicographically equal.

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

Related questions