java.util.StringTokenizer.hasMoreElements() Method


Advertisements


Description

The hasMoreElements() method is used to return the same value as the hasMoreTokens method. It exists so that this class can implement the Enumeration interface.

Declaration

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

public boolean hasMoreElements()

Parameters

NA

Return Value

The method call returns 'true' if there are more tokens; false otherwise.

Exception

NA

Example

The following example shows the usage of java.util.StringTokenizer.hasMoreElements()

Live Demo
package com.tutorialspoint;

import java.util.*;

public class StringTokenizerDemo {
   public static void main(String[] args) {

      // creating string tokenizer
      StringTokenizer st = new StringTokenizer("Come to learn");

      // checking elements
      while (st.hasMoreElements()) {
         System.out.println("Next element : " + st.nextElement());    
      }
   }
}

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

Next element : Come
Next element : to
Next element : learn

java_util_stringtokenizer.htm

Advertisements