java문자열위치찾기

    [JAVA] 문자열의 위치 찾기 indexOf(), lastlndexOf()

    자바 String의 indexOf()와 lastIndexOf()는 String에서 특정 문자열의 인덱스를 찾는데 사용하는 메서드이다. indexOf(String) : 첫 번째 문자열부터 찾고, 문자열의 시작 index를 리턴. indexOf(String, int) : 시작 위치를 부여, 부여된 위치부터 시작하여 문자열의 위치 index를 리턴 두 메서드 모두 원하는 String 못찾으면 -1을 리턴 한다. String hello = "HelloWorld HelloWorld"; System.out.println(hello.indexOf("World")); System.out.println(hello.indexOf("World", 6)); System.out.println(hello.indexOf("Worl..