无涯教程-Java - CharSequence subSequence(int beginIndex, int endIndex)函数

73 阅读1分钟

此方法返回一个新的字符序列,该序列是该序列的子序列。

CharSequence subSequence - 语法

public CharSequence subSequence(int beginIndex, int endIndex)

这是参数的详细信息-

  • beginIndex    -  包含开始索引。

  • endIndex       -  不包含结束索引。

CharSequence subSequence - 返回值

  • 此方法返回指定的子序列。

CharSequence subSequence - 示例

import java.io.*;
public class Test {

   public static void main(String args[]) {
      String Str=new String("Welcome to Learnfk.com");

      System.out.print("返回值 :" );
      System.out.println(Str.subSequence(0, 10) );

      System.out.print("返回值 :" );
      System.out.println(Str.subSequence(10, 15) );
   }
}

这将产生以下输出-

返回值 :Welcome to
返回值 : Lear

参考链接

www.learnfk.com/java/java-s…