Check the API documentation: Discover
StringTokenizer is a legacy class that is retained for compatibility reasons (although it is not encouraged in new code). It is recommended that all people seeking this function use the split method of String or the Java.util.regex package.
Since there is no need to advocate, the code try not to use these, or simply understand the following usage: Typically 3 methods are used together, iteration:
Method 1:
Public StringTokenizer (String str, String Delim, Boolean returndelims)
If the RETURNDELIMS flag is true, the delimiter character is also returned as a token. Each delimiter is returned as a string of length 1. If the flag is false, the delimiter is skipped, just as a delimiter between tokens.
Note that if Delim is null, this construction method does not throw an exception. However, attempting to invoke other methods on the resulting stringtokenizer may throw nullpointerexception.
Parameters:
STR-the string to parse.
Delim-delimiter.
Returndelims-Indicates whether the delimiter is returned as a flag.
Thrown:
NullPointerException-if STR is null.
Method 2:
Public String NextToken ()
Returns the next token of this string tokenizer.
Return:
The next token of this string tokenizer.
Thrown:
Nosuchelementexception-If there are no more tokens in this tokenizer string.
Method 3:
public boolean hasmoreelements ()
True if there are more tokens, otherwise false.
An example:
StringTokenizer test = new StringTokenizer ("aa=cc", "=", true);
while (Test.hasmoreelements ()) {
System.out.println (Test.nexttoken ());
}
return: AA = CC
Now this method is deprecated and is intended to be compatible with the previous code:
The split method of String or the Java.util.regex package.
String[] result = "This is a Test". Split ("\\s"); for (int x=0; x<result.length; x + +) System.out.println (result[x]);
StringTokenizer a simple description