countTokens(): This method is available in java.util.StringTokenizer class of Java.
Syntax:
int java.util.StringTokenizer.countTokens()
This method calculates the number of times that this tokenizer's nextToken method can be called before it generates an exception.
Parameters: NA
Returns: the number of tokens remaining in the string using the current delimiter set.
Exceptions: NA
Approach
Java
import java.util.StringTokenizer;public class StringTokenizercountTokens {public static void main(String[] args) {StringTokenizer stringTokenizer =new StringTokenizer("Hello Java Program");System.out.println(stringTokenizer.countTokens());}}
Output:
3
No comments:
Post a Comment