How to find the index of the last occurrence of a character in a String with Java

1 Answer

0 votes
package javaapplication1;

public class JavaApplication1 {

    public static void main(String[] args) {

        String s = new String("Java Programming");
      
        System.out.println(s.lastIndexOf('J'));
        System.out.println(s.lastIndexOf('m'));
        System.out.println(s.lastIndexOf('s'));
  }
}
  
/*
run:

0
12
-1

*/

 



answered Sep 22, 2016 by avibootz
...