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,

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

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,

Java string startswith method offset

String startsWith(String prefix) method in Java
String subSequence(int beginIndex, int endIndex) method in Java
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment