java.util.StringTokenizer
java.lang.Object
None
java.util.Enumeration
JDK 1.0 or later
The StringTokenizer class implements a simple, delimiter-based string tokenizer. In other words, a StringTokenizer is used to break a String into tokens separated by delimiter characters. By default, the class uses the standard whitespace characters as delimiters, but you can specify any delimiter characters you want, either when the StringTokenizer is created or on a token-by-token basis. You can also specify whether the delimiters are returned as tokens or not. A StringTokenizer returns the tokens in its String in order, either as String objects or as Objects in an Enumeration.
StringTokenizer shouldn't be confused with the more complex java.io.StreamTokenizer, which parses a stream into tokens that are similar to those used in the Java language.
public class java.util.StringTokenizer extends java.lang.Object implements java.util.Enumeration { // Constructors public StringTokenizer(String str); public StringTokenizer(String str, String delim); public StringTokenizer(String str, String delim, boolean returnTokens); // Instance Methods public int countTokens(); public boolean hasMoreElements(); public boolean hasMoreTokens(); public Object nextElement(); public String nextToken(); public String nextToken(String delim); }
The String to be tokenized.
This constructor creates a StringTokenizer that breaks apart the given string using the default delimiter characters. The default delimiters are the standard whitespace characters: space, tab (\t), carriage return (\r), and newline (\n).
The String to be tokenized.
The delimiter characters.
This constructor creates a StringTokenizer that breaks apart the given string using the characters in delim as delimiter characters.
public StringTokenizer(String str, String delim, boolean returnTokens)
The String to be tokenized.
The delimiter characters.
A boolean value that indicates whether or not delimiters should be returned as tokens.
This constructor creates a StringTokenizer that breaks apart the given string using the characters in delim as delimiter characters. If returnTokens is true, the delimiters are returned as tokens; otherwise they are skipped.
The number of tokens remaining in the string.
This method returns the number of tokens that remain in the string, which is the same as the number of times nextToken() can be called before an exception is thrown.
true if there are more tokens to be returned; false otherwise.
Enumeration.hasMoreElements()
This method returns the result of calling hasMoreTokens().
true if there are more tokens to be returned; false otherwise.
This method returns true if this object has more tokens to return.
The next token as an Object.
If there are no more tokens in the string.
Enumeration.nextElement()
This method returns result of calling nextToken().
The next token as a String.
If there are no more tokens in the string.
This method returns the next token.
The delimiter characters.
The next token as a String.
If there are no more tokens in the string.
This method sets the delimiter characters to the characters in the given string and then returns the next token. The change in delimiters persists until another call to this method changes them again.
Method | Inherited From | Method | Inherited From |
---|---|---|---|
clone() |
Object |
equals(Object) |
Object |
finalize() |
Objxect |
getClass() |
Object |
hashCode() |
Object |
notify() |
Object |
notifyAll() |
Object |
toString() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
Enumeration, NoSuchElementException, StreamTokenizer, String