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
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: java.lang.String.startsWith()
Post your Comment