xxxxxxxxxx
String str = "Hello";
//This will return true because string str starts with "He"
str.startsWith("He");
xxxxxxxxxx
public class StringExample
{
public static void main(String[] args)
{
String blogName = "howtodoinjava.com";
System.out.println( blogName.startsWith("how") ); //true
System.out.println( "howtodoinjava.com".startsWith("howto") ); //true
System.out.println( "howtodoinjava.com".startsWith("hello") ); //false
}
}
xxxxxxxxxx
String str = "Hello, world!";
String prefix = "Hello";
if (str.startsWith(prefix)) {
System.out.println("The string starts with the prefix.");
} else {
System.out.println("The string does not start with the prefix.");
}