.subSequence()
.subSquence()
is a String
method that returns a new character sequence that is a substring of a given string.
Syntax
str.subSequence(int startIndex, int endIndex)
The .subSequence()
method will return a substring of the str
string from startIndex
to endIndex
- 1.
The .subSquence()
method takes two parameters:
startIndex
- the starting index (inclusive).endIndex
- the ending index (exclusive).
Both parameters must be integers.
Example
The following example will return a substring of the str
string.
class Main {public static void main(String[] args) {String str = "Java Programming";System.out.println(str.subSequence(0, 4));}}
This will print:
Java
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.