String Methods

AP Computer Science A· difficulty 3/5

String s = "banana";
System.out.println(s.indexOf('a'));

What is printed?

  • A

    5

  • B

    0

  • C

    3

  • D

    1

    check_circle

Explanation

indexOf returns the index of the first occurrence; the first 'a' in "banana" is at index 1.

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

Related questions