String Substring Method Behavior
All of the following statements about the String class’s substring method are true EXCEPT:
public class TestSubstring {
public static void main(String[] args) {
String s = "AP Computer Science";
String sub = s.substring(3, 11);
System.out.println(sub);
}
}
A
Providing indices outside the valid range causes substring to throw an IndexOutOfBoundsException at runtime.
B
When a non-zero start index is provided, substring returns the entire original string.
C
If the indices provided are within range, substring returns a new String representing the specified section of the original.
D
The substring method returns a portion of the string from the start index (inclusive) to the end index (exclusive).
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | kaisuki | 1 | 1 | 0m 00s | 100 |
| #2 | richa.tuli | 1 | 1 | 0m 21s | 79 |
| #3 | jeonsaw1723 | 1 | 2 | 1m 42s | -12 |
| #4 | y.seong2027 | 1 | 3 | 3m 26s | -126 |
| #5 | psak12 | 1 | 2 | 3m 42s | -132 |
| #6 | lsj08030922 | 1 | 2 | 32m 32s | -1,862 |
APFIVE