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
If the indices provided are within range, substring returns a new String representing the specified section of the original.
B
When a non-zero start index is provided, substring returns the entire original string.
C
Providing indices outside the valid range causes substring to throw an IndexOutOfBoundsException at runtime.
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 | liuwilliam072410 | 1 | 2 | 1m 39s | -9 |
| #4 | jeonsaw1723 | 1 | 2 | 1m 42s | -12 |
| #5 | y.seong2027 | 1 | 3 | 3m 26s | -126 |
| #6 | psak12 | 1 | 2 | 3m 42s | -132 |
| #7 | chunxiangxu.cxu | 0 | 3 | 5m 10s | -340 |
| #8 | lsj08030922 | 1 | 2 | 32m 32s | -1,862 |
Items per page:
10
1 – 8 of 8
APFIVE