Java StringTokenizer - hasMoreTokens() Method
The java.util.StringTokenizer.hasMoreTokens() method is used to test if there are more tokens available from this tokenizer's string. If this method returns true, then a subsequent call to nextToken with no argument will successfully return a token.
Syntax
public boolean hasMoreTokens()
Parameters
No parameter is required.
Return Value
Returns true if and only if there is at least one token in the string after the current position; false otherwise.
Exception
NA
Example:
In the example below, the java.util.StringTokenizer.hasMoreTokens() method is used to display the content of 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 string tokenizer. System.out.println("StringTokenizer contains: "); while(st.hasMoreElements()) System.out.println(st.nextElement()); } }
The output of the above code will be:
StringTokenizer contains: Alpha Coding Skills
❮ Java.util - StringTokenizer