How to check if a string starts and ends with another string in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String s = "java c php python java";

        if (s.startsWith("java") && s.endsWith("java"))
            System.out.println("yes");
        else
            System.out.println("no");
    }
}
 
 
 
/*
run:
 
yes
 
*/

 



answered Nov 16, 2019 by avibootz

Related questions

...