How to check if a string is start with a specified word in Java

2 Answers

0 votes
package javaapplication1;

public class JavaApplication1 {
    
    public static void main(String[] args) {
  
        String s = "java php c++ PHP";
         
        if (s.startsWith("java")) {
            System.out.println("starts with java");
        } else {
            System.out.println("not start with java");
        }
    }    
}
   
/*
   
run:
   
starts with java
   
*/

 



answered Oct 27, 2016 by avibootz
0 votes
package javaapplication1;

public class JavaApplication1 {
    
    public static void main(String[] args) {
  
        String s = "php java php c++ PHP";
         
        if (s.startsWith("PHP")) {
            System.out.println("starts with PHP");
        } else {
            System.out.println("not start with PHP");
        }
    }    
}
   
/*
   
run:
   
not start with PHP
   
*/

 



answered Oct 27, 2016 by avibootz

Related questions

...