Java String startsWith(String prefix)Example
String class startsWith(String prefix) method example
String class startsWith(String prefix) method example. This example shows you how to use startsWith(String prefix) method.This method Tests if this string starts with the specified prefix.
Here is the code:-
/**
* @(#) StartsWithstring.java
*Program to tests if this string starts with the specified prefix.
* @Version 01-May-2008
* @author Rose India Team
*/
public class StartsWithstring
{
public static void main(String[] args)
{
String str1 = "RoseIndia is my Team.";
String str2 = "I works with RoseIndia.";
// String to check the above two Strings to see if they start with this value (r).
String checkstring = "R";
/* Checking if either of the above two Strings start with 'R'or not..
boolean is taken so that it may return true and false*/
boolean s1 = str1.startsWith(checkstring);
boolean s2 = str2.startsWith(checkstring);
// Display the results of the startsWith calls.
System.out.println("\"" + str1 + "\"starts with " +
"\"" + checkstring + "\":- " + s1);
System.out.println("\"" + str2 + "\" starts with " +
"\"" + checkstring + "\":- " + s2);
}
} |
null
|