String Methods

AP Computer Science A· difficulty 3/5

String s = "abcdef";
System.out.println(s.indexOf("xyz"));

What is printed?

  • A

    -1

    check_circle
  • B

    6

  • C

    0

  • D

    null

Explanation

indexOf returns -1 when the searched substring is not found.

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

Related questions