14 May String startsWith(String prefix, int toffset) method in Java
The startsWith(String prefix, int toffset) method in Java tests if this string starts with the specified prefix beginning a specified index.
Syntax
Let us see the syntax,
1 2 3 |
boolean startsWith(String prefix, int toffset) |
Parameters
Let us see the parameters,
- prefix− the prefix
- toffset− where to begin looking in the string
Example
The following is an example of boolean startsWith (String prefix, int toffset),
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
public class StudyopediaDemo { public static void main(String args[]) { String message = new String("Studyopedia provides free learning content!"); System.out.println("String: "+message); System.out.print("Result= " ); System.out.println(message.startsWith("learning",26)); System.out.print("Result= " ); System.out.println(message.startsWith("content",15)); System.out.print("Result= " ); System.out.println(message.startsWith("Studyopedia",0)); System.out.print("Result= " ); System.out.println(message.startsWith("Study",0)); } } |
Output
The following is the output,
No Comments