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

貢獻/合作者

正在開放中...
 

評論(條)

  • 還冇有評論!