Java startsWith() method

    startsWith() method

    This method will allow you to check if the specified string will start with the given prefix or not. If the string starts with the particular prefix then it will return true else the false value will get returned.

    Syntax-

    public boolean startsWith(String prefix)  
    
    public boolean startsWith(String prefix, int offset)  

    Example-

    public class Simple{  
    
       public static void main(String[] args) {      
          String s1="welcome to Java and welcome to tutorial";  
          System.out.println(s1.startsWith("wel")); 
          System.out.println(s1.startsWith("WELCOME TO"));  
       }
    }  

    Output-

    Example-

    public class Simple{  
       public static void main(String[] args) {      
          String s1="welcome to Java and welcome to tutorial";  
          System.out.println(s1.startsWith("c",3));  
       }
    }  

    Output-