The nextElement() method of StringTokenizer class is also used to return the next token one after another from this StringTokenizer. It is similar to the nextToken() method, except that the return type is Object rather than the String.
public Object nextElement()
Parameters: The method does not take any parameters.
Return Value: The method returns the next token present in the line of the string tokenizer.
Below programs illustrate the working of nextElement() Method of StringTokenizer:
The Next token: Lets The Next token: practice The Next token: at The Next token: GeeksforGeeks
The Next token: Welcome The Next token: to The Next token: GeeksforGeeks
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.