Java String.subSequence() – Java String.subSequence()

最后修改: 2017年 11月 9日

中文/混合/英文(键盘快捷键:t)

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().

方法subSequence()获得一个String的一部分,给定起始索引和结果的长度。方法SubSequence()的行为方式与substring()相同。

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

唯一的区别是,它返回一个CharSequence,而不是一个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()