Back to questions
JuniorTheoryCommon
What does the program print?
public class Main {
public static void main(String[] args) {
String s = "interview";
System.out.println(s.substring(2, 5));
}
}ter
- Expecting
terv: the end index ofsubstringis not included, sosubstring(2, 5)stops before index 5 and returns three characters. - Expecting
nte: string indexes start at 0, like array indexes, so index 2 is the third character,t.
- What does
s.substring(2)return for the same string? - What happens when
substringgets an end index larger than the length of the string?