logo

Java String SubSequence() Method


Show

Description

String. subSequence() is a built-in meaning in Java that revisits a CharSequence. CharSequence that is a follows of this sequence. The subsequence begins with the char value at the specified index and ends with the char value at (end-1).

Syntax

Here is the syntax of this method:

public CharSequence subSequence(int beginIndex, int endIndex)

Parameters

Here is the detail of parameters:

  • beginIndex − the begin index, inclusive.
  • endIndex − the end index, exclusive.

Return Value

  • This method returns the specified subsequence.

Example

import java.io.*;
public class Test {

   public static void main(String args[]) {
      String Str = new String("Welcome to Intellinuts.com");

      System.out.print("Return Value :" );
      System.out.println(Str.subSequence(0, 10) );

      System.out.print("Return Value :" );
      System.out.println(Str.subSequence(10, 12) );
   }
}

This will produce the following result:

Output

Return Value :Welcome to
Return Value : Inte

Here at Intellinuts, we have created a complete Java tutorial for Beginners to get started in Java.