java.lang.StringBuffer subSequence(int start,int end)

Syntax:

public CharSequence subSequence(int start,int end)

Java Code Example :

This java example source code demonstrates the use of subSequence(int start,int end)  method of StringBuffer class. Initially the code assigns a string “javatutorialhq.com” as initial contents of the string buffer. Then we use the subsequence to get a part of the sequence based from index 3 until the end index 10.

This method will result to the same value as that of substring(int start, int end) its just that in this case the result is a CharSequence object.

Make a note that IndexOutOfBoundsException will be thrown if start or end are negative or greater than length(), or start is greater than end.

Sample Output :

Running the above example source code will give the following output

subSequence(int start,int end) method example

subSequence(int start,int end) method example

Suggested Reading List :

References :