java.lang.String.startsWith()

String class method - startsWith()

java.lang.String.startsWith()

java.lang.String.startsWith()

String.startsWith() is again a String Class method of Java that checks if the given string starts with the prefix char or not.

It take parameters..
prefix - the prefix of the string.

Syntax of the String.startsWith() method

public boolean startsWith(String prefix)

a Simple Example:

Example
{
public static void main(String[] args)
{
String str1 = "Awards for Small Businesse.";
String str2 = "Small business market.";

String startStr = "Sm";

boolean starts1 = str1.startsWith(startStr);
boolean starts2 = str2.startsWith(startStr);

System.out.println("\"" + str1 + "\" starts with " +
"\"" + startStr + "\"? " + starts1);
System.out.println("\"" + str2 + "\" starts with " +
"\"" + startStr + "\"? " + starts2);
}
}

the Output is:

"Awards for Small Businesse." starts with "Sm"? false
"Small business market." starts with "Sm"? true