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

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 05-Jul-2019 10:34:56
Advertisements