StringTokenizer nextToken() Method in Java with Examples Last Updated : 29 Jan, 2019 Comments Improve Suggest changes Like Article Like Report 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 // 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: GeeksforGeeks Example 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 Comment More infoAdvertise with us Next Article StringTokenizer nextToken() Method in Java with Examples chinmoy lenka Follow Improve Article Tags : Misc Java Java - util package Java-Functions Java-StringTokenizer +1 More Practice Tags : JavaMisc Similar Reads StringTokenizer nextElement() Method in Java with Examples 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. Syntax: public Object nextElement() Parameters: The method does 2 min read Scanner nextBoolean() method in Java with Examples The nextBoolean() method of java.util.Scanner class scans the next token of the input as a Boolean. If the translation is successful, the scanner advances past the input that matched. Syntax: public boolean nextBoolean() Parameters: The function does not accepts any parameter. Return Value: This fun 4 min read StringCharacterIterator next() method in Java with Examples The next() method of java.text.StringCharacterIterator class in Java is used to get the next character that is to be read by this StringCharacterIterator. This method decrements this iterator to one index forward and returns that next character. Syntax: public char next() Parameter: This method do n 1 min read Scanner nextLine() method in Java with Examples The nextLine() method of java.util.Scanner class advances this scanner past the current line and returns the input that was skipped. This function prints the rest of the current line, leaving out the line separator at the end. The next is set to after the line separator. Since this method continues 2 min read StringTokenizer countTokens() Method in Java with Examples The countTokens() method of StringTokenizer class calculate the number of times that this tokenizer's nextToken method can be called before the method generates any further exception. Note: The current position is not advanced during the process. Syntax: public int countTokens() Parameters: The meth 2 min read Scanner nextShort() method in Java with Examples The nextShort(radix) method of java.util.Scanner class scans the next token of the input as a short. If the translation is successful, the scanner advances past the input that matched. If the parameter radix is not passed, then it behaves similarly as nextShort(radix) where the radix is assumed to b 5 min read StringTokenizer hasMoreTokens() Method in Java with Examples The hasMoreTokens() method of StringTokenizer class checks whether there are any more tokens available with this StringTokenizer. Syntax: public boolean hasMoreTokens() Parameters: The method does not take any parameters. Return Value: The method returns boolean True if the availability of at least 2 min read Scanner toString() method in Java with Examples The toString() method of java.util.Scanner class returns the string representation of this Scanner. The exact format is unspecified. Syntax: public String toString() Return Value: This function returns the string representation of this scanner. Below program illustrates the above function: Program 1 1 min read StringCharacterIterator setText() method in Java with Examples The setText() method of java.text.StringCharacterIterator class in Java is used to set the current text that is to be read by this StringCharacterIterator. This method takes the text to be set as a parameter and sets the text of this StringCharacterIterator at that text. Syntax: public void setText( 1 min read String replace() method in Java with Examples The String replace() method returns a new string after replacing all the old characters/CharSequence with a given character/CharSequence. Example:Return a new string where all " o" characters are replaced with "p" character: Java // Java program to demonstrate // the replace() method public class Ma 4 min read Like