java.lang.String.startsWith()

String class method - startsWith()


 
Ads

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

 

Advertisements

Share on Google+Share on Google+

java.lang.String.startsWith()

Posted on: March 17, 2005 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: java.lang.String.startsWith()  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads