The hasMoreElements() method of StringTokenizer class also checks whether there are any more tokens available with this StringTokenizer. It is similar to the hasMoreTokens(). The method exists exclusively so that the Enumeration interface of this class can be implemented.
public boolean hasMoreElements()
Parameters: The method does not take any parameters.
Return Value: The method returns boolean True if the availability of at least one more token is found in the string after the current position else false.
Below programs illustrate the working of hasMoreElements() Method of StringTokenizer:
The number of Tokens are: 4 true The Next token: Lets The Next token: practice The Next token: at The Next token: GeeksforGeeks
The number of Tokens are: 0 false
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.