Java API Tutorial - 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;
/*  w w w  . j  a v  a 2  s.  c o 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.