String Methods

AP Computer Science A· difficulty 4/5

String s = "abcdef";
System.out.println(s.substring(0, s.length()));

What is printed?

  • A

    abcdef

    check_circle
  • B

    abcde

  • C

    Error

  • D

    bcdef

Explanation

substring(0, length()) returns the entire string; it is legal because the end index can equal length().

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

Related questions