When a StringTokenizer is instantiated with a String , it breaks the string up into tokens separated by any of the characters in the specified string of delimiters. (For example, words separated by space and tab characters are tokens.) The hasMoreTokens( ) and nextToken( ) methods obtain the tokens in order. countTokens( ) returns the number of tokens in the string. StringTokenizer implements the Enumeration interface, so you may also access the tokens with the familiar hasMoreElements( ) and nextElement( ) methods. When you create a StringTokenizer , you can specify a string of delimiter characters to use for the entire string, or you can rely on the default whitespace delimiters. You can also specify whether the delimiters themselves should be returned as tokens. Finally, you can optionally specify a new string of delimiter characters when you call nextToken( ) . Figure 16-59. java.util.StringTokenizerpublic class StringTokenizer implements Enumeration<Object> { // Public Constructors public StringTokenizer (String str ); public StringTokenizer (String str , String delim ); public StringTokenizer (String str , String delim , boolean returnDelims ); // Public Instance Methods public int countTokens ( ); public boolean hasMoreTokens ( ); public String nextToken ( ); public String nextToken (String delim ); // Methods Implementing Enumeration public boolean hasMoreElements ( ); public Object nextElement ( ); } |