How to find start index of a first and last word in a string with Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String s = "Java is a general-purpose programming language, object-oriented programming";
        String word = "programming";

        System.out.println(s.indexOf(word)); 
        System.out.println(s.lastIndexOf(word)); 
    }
}


/*
run:

26
64

*/

 



answered Apr 27, 2019 by avibootz

Related questions

...