How to get the index of the last occurrence of specified character in a string with Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String str = "c c++ csharp java php python";

        System.out.println(str.lastIndexOf('c'));
         
        System.out.println(str.lastIndexOf('a'));
         
        System.out.println(str.lastIndexOf('p'));
    }
}
 
 
 
 
/*
run:
 
6
16
22
 
*/

 



answered Sep 4, 2022 by avibootz
...