Java StringTokenizer - nextElement() Method
The java.util.StringTokenizer.nextElement() method returns the same value as the nextToken method, except that its declared return value is Object rather than String. It exists so that this class can implement the Enumeration interface.
Syntax
public Object nextElement()
Parameters
No parameter is required.
Return Value
Returns the next token in the string.
Exception
Throws NoSuchElementException if there are no more tokens in this tokenizer's string.
Example:
In the example below, the java.util.StringTokenizer.nextElement() method returns the next token from the given string tokenizer.
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 StringTokenizer 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