StringTokenizer in Java
The java.util.StringTokenizer class allows you to break a string into tokens. It is simple way to break string.
It doesn't provide the facility to differentiate numbers, quoted strings, identifiers etc. like StreamTokenizer class. We will discuss about the StreamTokenizer class in I/O chapter.
Constructors of StringTokenizer class
There are 3 constructors defined in the StringTokenizer class.
Methods of StringTokenizer class
The 6 useful methods of StringTokenizer class are as follows:
Simple example of StringTokenizer class
Let's see the simple example of StringTokenizer class that tokenizes a string "my name is khan" on the basis of whitespace.
Output:my name is khan
Example of nextToken(String delim) method of StringTokenizer class
Output:Next token is : my
StringTokenizer class is deprecated now. It is recommended to use split() method of String class or regex (Regular Expression).