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.

Example

 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());
   }
}

Output

Total tokens : 5

Updated on: 29-Jun-2020

153 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements