How to get the index of first occurrence of substring in a string with Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String s = "python java c++ c c# php";
        
        int index = s.indexOf("java");
                 
        System.out.println(index);
    }
}
     
     
     
     
/*
run:
 
7
     
*/

 



answered Mar 19, 2021 by avibootz
...