Last Updated : 29 Jan, 2019
The
nextToken()method of
StringTokenizer classis used to return the next token one after another from this StringTokenizer.
Syntax:public String nextToken()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 nextToken() Method of StringTokenizer:
Example 1: Java
// Java code to illustrate nextToken() method
import java.util.*;
public class StringTokenizer_Demo {
public static void main(String args[])
{
// Creating a StringTokenizer
StringTokenizer str_arr
= new StringTokenizer(
"Lets practice at GeeksforGeeks");
// Displaying the Tokens
while (str_arr.hasMoreTokens()) {
System.out.println("The Next token: "
+ str_arr.nextToken());
}
}
}
Output:
The Next token: Lets The Next token: practice The Next token: at The Next token: GeeksforGeeksExample 2: Java
// Java code to illustrate nextToken() method
import java.util.*;
public class StringTokenizer_Demo {
public static void main(String args[])
{
// Creating a StringTokenizer
StringTokenizer str_arr
= new StringTokenizer(
"Welcome to GeeksforGeeks");
// Displaying the Tokens
while (str_arr.hasMoreTokens()) {
System.out.println("The Next token: "
+ str_arr.nextToken());
}
}
}
Output:
The Next token: Welcome The Next token: to The Next token: GeeksforGeeks
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4