StringTokenizer in JavaThe 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 classThere are 3 constructors defined in the StringTokenizer class.
Methods of StringTokenizer classThe 6 useful methods of StringTokenizer class are as follows:
Simple example of StringTokenizer classLet'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 classOutput:Next token is : my StringTokenizer class is deprecated now. It is recommended to use split() method of String class or regex (Regular Expression). Next TopicJava String FAQs
|