Java StringTokenizer .hasMoreTokens ()

Syntax

StringTokenizer.hasMoreTokens() has the following syntax.

public boolean hasMoreTokens()

Example

In the following code shows how to use StringTokenizer.hasMoreTokens() method.


import java.util.StringTokenizer;
/*ww w.j av a2  s .co m*/
public class Main {
   public static void main(String[] args) {
      
      StringTokenizer st = new StringTokenizer("tutorial from java2s.com");
      
      // counting tokens
      System.out.println("Total tokens : " + st.countTokens()); 
      
      // checking tokens
      while (st.hasMoreTokens()){
         System.out.println("Next token : " + st.nextToken());    
      }
   }    
}

The code above generates the following result.