What is the significance of the StringTokenizer class of the Java? Explain with an example?

The java.util.StringTokenizer class allows an application to break a string into tokens.

  • This class is a legacy class that is retained for compatibility reasons although its use is discouraged in new code.

  • Its methods do not distinguish among identifiers, numbers, and quoted strings.

  • This class methods do not even recognize and skip comments.


 Live Demo

import java.util.*;
public class StringTokenizerDemo {
   public static void main(String[] args) {
      // creating string tokenizer
      StringTokenizer st = new StringTokenizer("Tutorialspoint is the best site");
      // counting tokens
      System.out.println("Total tokens : " + st.countTokens());


Total tokens : 5