Java subSequence() Method

Java String类Java String Class


subSequence() method returns a new character sequence that is a subsequence of this sequence.

Syntax

public CharSequence subSequence(int beginIndex, int endIndex)

Parameters

  • beginIndex-- start index (inclusive).

  • endIndex-- end index (exclusive).

Return Value

Returns a new character sequence that is a subsequence of this sequence.

Example

public class Test {
    public static void main(String args[]) {
         String Str = new String("www.example.com");

         System.out.print("返回值 :" );
         System.out.println(Str.subSequence(4, 10) );
    }
}

The output of the above program is:

返回值 :example

Java String类Java String Class

Other Extensions