Java Utility Library

Java StringTokenizer - hasMoreElements() Method



The java.util.StringTokenizer.hasMoreElements() method returns the same value as the hasMoreTokens method. It exists so that this class can implement the Enumeration interface.

Syntax

public boolean hasMoreElements()

Parameters

No parameter is required.

Return Value

Returns true if there are more tokens; false otherwise.

Exception

NA

Example:

In the example below, the java.util.StringTokenizer.hasMoreElements() method is used to display the content of the given StringTokenizer.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a string tokenizer.
    StringTokenizer st = new StringTokenizer("Alpha,Coding,Skills", ",");

    //printing tokens of the string tokenizer.
    System.out.println("StringTokenizer contains: ");
    while(st.hasMoreElements()) 
      System.out.println(st.nextElement());  
  }
}

The output of the above code will be:

StringTokenizer contains: 
Alpha
Coding
Skills

❮ Java.util - StringTokenizer