php    php100   android
当前位置:首页 » java.lang包 »

Java.lang.String.subSequence()方法实例

评论  编辑

描述

The java.lang.String.subSequence() method returns a new character sequence that is a subsequence of this sequence.

声明

Following is the declaration for java.lang.String.subSequence() method

public CharSequence subSequence(int beginIndex, int endIndex)

参数

  • beginIndex -- This is the value of begin index, inclusive.

  • endIndex -- This is the value of the end index, exclusive.

返回值

This method returns the specified subsequence.

异常

  • IndexOutOfBoundsException -- if beginIndex or endIndex are negative, if endIndex is greater than length(), or if beginIndex is greater than startIndex.

实例一

编辑 +分享实例

以下例子将告诉你如何使用 java.lang.String.subSequence() method.

package gitbook.net;

import java.lang.*;

public class StringDemo {

  public static void main(String[] args) {
  
    String str = "Tutorials Point!";

    System.out.println("string = " + str);
    
    // returns the specified subsequence from index 2 to 9
    System.out.println("string subsequence = " + str.subSequence(2,9));
  }
}

编译和执行以上程序,将得到以下的结果:

string = Tutorials Point!
string subsequence = torials

贡献/合作者

正在开放中...
 

评论(条)

  • 还没有评论!