[Java] 문자열의 특정 문자 인덱스 찾기(indexOf, lastIndexOf) 1. indexOf public int indexOf(int ch) : 매개 값으로 주어진 int(아스키코드)로 시작되는 인덱스를 반환합니다. public int indexOf(int ch, int fromIndex) : fromIndex로 탐색 시작 지점을 지정합니다. public int indexOf(String str) : 매개 값으로 주어진 문자열이 시작되는 인덱스를 반환합니다. public int indexOf(String str, int fromIndex) : fromIndex로 탐색 시작 지점을 지정합니다. 주어진 문자가 포함되어있지 않으면 -1을 반환합니다. 예시 String test = "past is just past"; // public int indexOf(int ch), publi.. Backend/Java 3년 전
[Java] 문자열 인덱스 위치로 자르기(substring) 1. substring(int beginIndex) public String substring(int beginIndex) : beginIndex 위치에서 끝까지 잘라낸 새로운 문자열을 리턴 예시 1) String test = "The name of this blog is Coding Tree."; String substring = test.substring(25); // 25번 인덱스부터 끝까지 잘라서 반환 System.out.println(substring); // Coding Tree. 예시 2) public int indexOf(String str) : 문자열 내에서 주어진 문자열의 위치를 리턴 (해당 문자가 없으면 -1) String test = "The name of this blog is C.. Backend/Java 3년 전