Java String subSequence() Method
Example
Return a sequence of characters from a string:
String myStr = "Hello, World!";
System.out.println(myStr.subSequence(7, 12));
Definition and Usage
The subSequence()
method returns a subsequence from the string as a CharSequence
object.
Syntax
public CharSequence subSequence(int start, int end)
Parameter Values
Parameter | Description |
---|---|
start | Required. The index of the character at which the subsequence starts. |
end | Required. The index after the last character of the subsequence. |
Technical Details
Returns: | A CharSequence containing a subsequence of the string. |
---|---|
Throws: | IndexOutOfBoundsException - If start or end are negative, start is greater than end or end is greater than the length of the string. |
Java version: | 1.4 |
❮ String Methods