로딩
요청 처리 중입니다...

특정문자위치 찾기(indexOf, lastIndexOf)

 특정문자위치 찾기(indexOf, lastIndexOf)

indexOf() indexOf()는 특정 문자나 문자열이 앞에서부터 처음 발견되는 인덱스를 반환하며 찾지 못할경우 -1을 반환한다. public class IndexOfTest{ public static void main(String[] args){ String indexOfTestOne = "Hello world"; String indexOfTestTwo = " Hello world "; System.out.println( indexOfTestOne.indexOf("o") ); // 4 System.out.println( indexOfTestOne.indexOf("x") ); // -1 System.out.println( indexOfTestOne.indexOf("o",5) ); // 7 System.out.println( indexOfTestTwo.indexOf("o") ); // 13 System.out.println( indexOfTestTwo.indexOf("el") );...