php    php100   android
當前位置:首頁 » Java.util包 »

java.util.StringTokenizer.hasMoreTokens()方法實例

評論  編輯

描述

The hasMoreTokens() method is used to test if there are more tokens available from this tokenizer's string.

聲明

Following is the declaration for java.util.StringTokenizer.hasMoreTokens() method.

public boolean hasMoreTokens()

參數

  • NA

返回值

The method call returns 'true' if and only if there is at least one token in the string after the current position; false otherwise.

異常

  • NA

實例一

編輯 +分享實例

以下例子將告訴你如何使用 java.util.StringTokenizer.hasMoreTokens()

package gitbook.net;

import java.util.*;

public class StringTokenizerDemo {
   public static void main(String[] args) {
      // creating string tokenizer
      StringTokenizer st = new StringTokenizer("Come to learn");
      
      // counting tokens
      System.out.println("Total tokens : " + st.countTokens()); 
      
      // checking tokens
      while (st.hasMoreTokens()){
         System.out.println("Next token : " + st.nextToken());    
      }
   }    
}

Let us compile and run the above program, this will produce the following result.

Total tokens : 3
Next token : Come
Next token : to
Next token : learn

貢獻/合作者

正在開放中...
 

評論(條)

  • 還冇有評論!