Java Check String Starts with Substring
In Java, you can use the startsWith() method to check if a string starts with a specific substring. For example:
String str = "Hello World";
if(str.startsWith("Hello")) {
System.out.println("String starts with 'Hello'");
} else {
System.out.println("String does not start with 'Hello'");
}
The above code will output:
String starts with 'Hello'
The startsWith() method returns true if the string starts with a specific substring; otherwise it returns false.