Say, String str = “hello world” ;
To, get hello, we can use str.subSequence(0, 5).
If it’s a 0-based indexed string, then why we don’t write str.subSequence(0.4) as ‘o’ has the index 4?
Say, String str = hello world ; To, get hello, we can use str.subSequence(0,
Share
Please see the javadoc for the method.
Returns a new character sequence that is a subsequence of this sequence.
An invocation of this method of the form
behaves in exactly the same way as the invocation
This method is defined so that the String class can implement the CharSequence interface.
Specified by:
subSequence in interface CharSequence
Parameters:
beginIndex – the begin index, inclusive.
endIndex – the end index, exclusive.
Returns:
the specified subsequence.
Throws:
IndexOutOfBoundsException – if beginIndex or endIndex are negative, if endIndex is greater than length(), or if beginIndex is greater than startIndex