String Methods

AP Computer Science A· difficulty 4/5

Which extracts the first character of <code>String s = "hello";</code>?

  • A

    s.char(1)

  • B

    s[0]

  • C

    s.charAt(0)

    check_circle
  • D

    s.first()

Explanation

<code>s.charAt(0)</code> returns <code>'h'</code> — strings are 0-indexed in Java.

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

Related questions