How to get the index of last occurrence of substring in StringBuffer with Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        StringBuffer sb = new StringBuffer("PHPJavaC++C#CPythonJava"); 

        System.out.println(sb.lastIndexOf("Java")); 
        System.out.println(sb.lastIndexOf("NodeJS")); 
    }
}


/*
run:

19
-1

*/

 



answered Apr 23, 2020 by avibootz
...