How to remove everything from a string after a specific word in Java

1 Answer

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

        System.out.println(str);
    }
}




/*
run:

java c c++

*/

 



answered Dec 6, 2022 by avibootz

Related questions

1 answer 125 views
1 answer 99 views
1 answer 104 views
1 answer 135 views
1 answer 145 views
1 answer 117 views
...