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.
public int countTokens()
Parameters: The method does not take any parameters.
Return Value: The method is used to return the number of tokens remaining in the string using the current delimiter set.
Below programs illustrate the working of countTokens() Method of StringTokenizer:
Total number of Tokens: 4 token at  : Lets token at  : practice token at  : at token at  : GeeksforGeeks
Total number of Tokens: 3 token at  : Welcome token at  : to token at  : GeeksforGeeks
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.