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,

Java string startswith method

String split(String regex, int limit) method in Java
String startsWith(String prefix, int toffset) method in Java
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment