Home Tutorials Java StringExamples java.lang.String.startsWith()
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

java.lang.String.startsWith()

Advertisement
String class method - 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

 

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 17, 2005

Ask Questions?    Discuss: java.lang.String.startsWith()  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com