StreamTokenizer provides similar functionality but the tokenization method is much simpler than the one used by the StreamTokenizer class. Methods of StringTokenizer do not distinguish among identifiers, numbers, and quoted strings, nor recognize and skip comments. The set of delimiters the characters that separate tokens may be specified either at the creation time or on a per-token basis. Using the StringTokenizer The simplest example of using StringTokenizer will be to split a String based on specified delimiters. Then in the loop, using tokens.
|Published (Last):||20 June 2005|
|PDF File Size:||4.41 Mb|
|ePub File Size:||15.79 Mb|
|Price:||Free* [*Free Regsitration Required]|
Most programmers opt to use StringTokenizer in tokenizing a string than StreamTokenizer because the methods are much simpler than the latter. The StringTokenizer methods do not distinguish among identifiers, numbers, and quoted strings, nor do they recognize and skip comments. The set of delimiters may be specified either at creation time or on a per-token basis. I hope this is clear enough, because we will be using these terms all throughout this tutorial. An instance of StringTokenizer behaves in one of two ways, depending on whether it was created with the returnDelims flag having the value true or false: If the flag is false, delimiter characters serve to separate tokens.
A token is a maximal sequence of consecutive characters that are not delimiters. If the flag is true, delimiter characters are themselves considered to be tokens. A token is thus either one delimiter character, or a maximal sequence of consecutive characters that are not delimiters. A StringTokenizer object internally maintains a current position within the string to be tokenized. Some operations advance this current position past the characters processed. A token is returned by taking a substring of the string that was used to create the StringTokenizer object.
StringTokenizer Class Syntax.
StringTokenizer in Java
All characters in the delim argument are the delimiters for separating tokens. If the returnDelims flag is true, then the delimiter characters are also returned as tokens. Each delimiter is returned as a string of length one. If the flag is false, the delimiter characters are skipped and only serve as separators between tokens.
Quick Guide to the Java StringTokenizer
Java StringTokenizer Class Tutorial and Example