Home >>Java String Methods >Java String startsWith() Method
Java startsWith() method in Java String is used to checks whether a string starts with the specified character.
public boolean startsWith(String chars)
char - This parameter is used to represents A String of the character to check for
Returns - It is used to returns a boolean value:
public class StartsWithExample1
{
public static void main(String[] args)
{
String Name = "Phptpoint";
System.out.println(Name.startsWith("Php"));
System.out.println(Name.startsWith("ptpo"));
System.out.println(Name.startsWith("int"));
}
}
public class StartsWithExample1
{
public static void main(String[] args)
{
String n1 = "Phptpoint";
System.out.println(n1.startsWith("P"));
System.out.println(n1.startsWith("t"));
System.out.println(n1.startsWith("i",1));
}
}