Java Top

To help you get access to the material during the current, global COVID-19 crisis, all courses are 30% off until July 2

>> GET ACCESS NOW

The method subSequence() obtains a part of a String given the starting index and the length of the result. The method SubSequence() behaves in the same way as substring().

The only difference is that it returns a CharSequence instead of a String.

Available Signatures

public CharSequence subSequence(int beginIndex, int endIndex)

Example

@Test
public void whenCallSubSequence_thenCorrect() {
    String s = "Welcome to Baeldung";
    
    assertEquals("Welcome", s.subSequence(0, 7));
}
Next »
Java String.substring()
« Previous
Java String.startsWith()
Java bottom

To help you get access to the material during the current, global COVID-19 crisis, all courses are 30% off until July 2

>> GET ACCESS NOW

Comments are closed on this article!