java.util.StringTokenizer.hasMoreTokens() Method
Advertisements
Description
The hasMoreTokens() method is used to test if there are more tokens available from this tokenizer's string.
Declaration
Following is the declaration for java.util.StringTokenizer.hasMoreTokens() method.
public boolean hasMoreTokens()
Parameters
NA
Return Value
The method call returns 'true' if and only if there is at least one token in the string after the current position; false otherwise.
Exception
NA
Example
The following example shows the usage of java.util.StringTokenizer.hasMoreTokens()
package com.tutorialspoint;
import java.util.*;
public class StringTokenizerDemo {
public static void main(String[] args) {
// creating string tokenizer
StringTokenizer st = new StringTokenizer("Come to learn");
// counting tokens
System.out.println("Total tokens : " + st.countTokens());
// checking tokens
while (st.hasMoreTokens()){
System.out.println("Next token : " + st.nextToken());
}
}
}
Let us compile and run the above program, this will produce the following result.
Total tokens : 3 Next token : Come Next token : to Next token : learn