String Methods

AP Computer Science A· difficulty 2/5

String s = "hello";
char c = s.charAt(1);
System.out.println(c);

What is printed?

  • A

    l

  • B

    e

    check_circle
  • C

    1

  • D

    h

Explanation

Indexing is zero-based; the character at index 1 of "hello" is 'e'.

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

Related questions