Java Utility Library

Java StringTokenizer - nextToken() Method



The java.util.StringTokenizer.nextToken() method returns the next token from this string tokenizer.

Syntax

public String nextToken()

Parameters

No parameter is required.

Return Value

Returns the next token from this string tokenizer.

Exception

NA

Example:

In the example below, the java.util.StringTokenizer.nextToken() 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.hasMoreTokens()) 
      System.out.println(st.nextToken());  
  }
}

The output of the above code will be:

Token Count is: 3

StringTokenizer contains: 
Alpha
Coding
Skills

❮ Java.util - StringTokenizer