StringTokenizer nextToken() Method in Java with Examples
The nextToken() method of StringTokenizer class is 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 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()); } } } |
chevron_right
filter_none
Output:
The Next token: Lets The Next token: practice The Next token: at The Next token: GeeksforGeeks
Example 2:
// 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()); } } } |
chevron_right
filter_none
Output:
The Next token: Welcome The Next token: to The Next token: GeeksforGeeks
Recommended Posts:
- StringTokenizer nextElement() Method in Java with Examples
- StringTokenizer hasMoreElements() Method in Java with Examples
- StringTokenizer hasMoreTokens() Method in Java with Examples
- StringTokenizer countTokens() Method in Java with Examples
- StringTokenizer methods in Java with Examples | Set 2
- StringTokenizer class in Java with example | Set 1 ( Constructors)
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java lang.Long.builtcount() method in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



