Java String startsWith(String prefix,int toffset) Example
String class startsWith(String prefix,int toffset)method example
String class startsWith(String prefix, int toffset) method example. This example shows you how to use startsWith(String prefix, int toffset) method.This method Tests if the substring of this string beginning at the specified index starts with the specified prefix.
Here is the code:-
/**
* @(#) StartsWith1string.java
*Program to Tests if this string starts with the specified prefix beginning a specified index.
* @Version 01-May-2008
* @author Rose India Team
*/
public class StartsWith1string
{
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'and with index 0 or not..boolean is taken so that it may return true and false*/
boolean s1 = str1.startsWith(checkstring,0);
boolean s2 = str2.startsWith(checkstring,2);
// Display the results of the startsWith calls.
System.out.println("\"" + str1 + "\"starts with " +
"\"" + checkstring + "\":- " + s1);
System.out.println("\"" + str2 + "\" starts with " +
"\"" + checkstring + "\":- " + s2);
}
} |
null
|