프로그래밍/JAVA
substring()
김태희천사v
2020. 2. 10. 03:56
"hello" 라는 문자열의 5번째 인덱스에서 에러가 발생할줄 알았는데 6번째에서 발생하네요
마지막인덱스 +1에 접근할 일은 없을것 같아서 따로 체크할 일은 아닌거 같다는 생각이 듭니다
하지만 현상이 신기해서 게시판에 글 써요 ㅋ
1
2
3
4
5
6
7
8
9
10
|
System.out.println("hello".substring(2)); // llo
System.out.println("hello".substring(3)); // lo
System.out.println("hello".substring(4)); // o
System.out.println("hello".substring(5)); //
// System.out.println("hello".substring(6)); // error
System.out.println("hello".substring(0,3)); // hel
System.out.println("hello".substring(0,4)); // hell
System.out.println("hello".substring(0,5)); // hello
|