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,
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),
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