14 May String startsWith(String prefix) method in Java
The startsWith(String prefix) method in Java tests if this string starts with the specified prefix.
Syntax
Let us see the syntax,
1 2 3 |
boolean startsWith(String prefix) |
Parameters
Let us see the parameters,
- prefix − prefix to be matched
Example
The following is an example of boolean startsWith(String prefix),
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")); System.out.print("Result= " ); System.out.println(message.startsWith("content")); System.out.print("Result= " ); System.out.println(message.startsWith("Studyopedia")); System.out.print("Result= " ); System.out.println(message.startsWith("Study")); } } |
Output
The following is the output,
No Comments