How to get the index of the last substring of a String using lastIndexOf() in Java

1 Answer

0 votes
package javaapplication1;

public class JavaApplication1 {

    public static void main(String[] args) {

        try {

            String s = "java c++ java";

            int i = s.lastIndexOf("java");
            System.out.println(i);

        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
}

/*
             
run:
       
9
    
 */

 



answered Nov 23, 2016 by avibootz
...