JAVA/JAVA Note

indexOf, lastindexOf

hoonssss 2023. 8. 16. 13:05
반응형
SMALL
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") );  // 10

    }
}
0~시작
public class IndexOfTest{
    public static void main(String[] args){

        String indexOfTestOne = "Hello world";

        System.out.println( indexOfTestOne.lastIndexOf("o") );  // 7
        System.out.println( indexOfTestOne.lastIndexOf("x") );  // -1
        System.out.println( indexOfTestOne.lastIndexOf("o",5) );  // 4

    }
}

 

반응형
LIST

'JAVA > JAVA Note' 카테고리의 다른 글

interface, 다형성  (0) 2023.08.16
예외처리  (0) 2023.08.16
try catch finally / try with resource statements  (0) 2023.08.16
StringBuilder sb = new StringBuilder();  (0) 2023.08.16
charAt, indexOf  (0) 2023.08.16