String Methods

AP Computer Science A· difficulty 2/5

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

What is printed?

  • A

    2

    check_circle
  • B

    3

  • C

    1

  • D

    -1

Explanation

The substring "cd" begins at index 2 in "abcdef".

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

Related questions