Class java.util.StringTokenizer
All Packages Class Hierarchy This Package Previous Next Index
Class java.util.StringTokenizer
java.lang.Object
|
+----java.util.StringTokenizer
- public class StringTokenizer
- extends Object
- implements Enumeration
StringTokenizer is a class that controls simple linear tokenization
of a String. The set of delimiters, which defaults to common
whitespace characters, may be specified at creation time or on a
per-token basis.
Example usage:
String s = "this is a test";
StringTokenizer st = new StringTokenizer(s);
while (st.hasMoreTokens()) {
println(st.nextToken());
}
Prints the following on the console:
this
is
a
test
-
StringTokenizer(String, String, boolean)
- Constructs a StringTokenizer on the specified String, using the
specified delimiter set.
-
StringTokenizer(String, String)
- Constructs a StringTokenizer on the specified String, using the
specified delimiter set.
-
StringTokenizer(String)
- Constructs a StringTokenizer on the specified String, using the
default delimiter set (which is " \t\n\r").
-
countTokens()
- Returns the next number of tokens in the String using
the current deliminter set.
-
hasMoreElements()
- Returns true if the Enumeration has more elements.
-
hasMoreTokens()
- Returns true if more tokens exist.
-
nextElement()
- Returns the next element in the Enumeration.
-
nextToken()
- Returns the next token of the String.
-
nextToken(String)
- Returns the next token, after switching to the new delimiter set.
StringTokenizer
public StringTokenizer(String str,
String delim,
boolean returnTokens)
- Constructs a StringTokenizer on the specified String, using the
specified delimiter set.
- Parameters:
- str - the input String
- delim - the delimiter String
- returnTokens - returns delimiters as tokens or skip them
StringTokenizer
public StringTokenizer(String str,
String delim)
- Constructs a StringTokenizer on the specified String, using the
specified delimiter set.
- Parameters:
- str - the input String
- delim - the delimiter String
StringTokenizer
public StringTokenizer(String str)
- Constructs a StringTokenizer on the specified String, using the
default delimiter set (which is " \t\n\r").
- Parameters:
- str - the String
hasMoreTokens
public boolean hasMoreTokens()
- Returns true if more tokens exist.
nextToken
public String nextToken()
- Returns the next token of the String.
- Throws: NoSuchElementException
- If there are no more
tokens in the String.
nextToken
public String nextToken(String delim)
- Returns the next token, after switching to the new delimiter set.
The new delimiter set remains the default after this call.
- Parameters:
- delim - the new delimiters
hasMoreElements
public boolean hasMoreElements()
- Returns true if the Enumeration has more elements.
nextElement
public Object nextElement()
- Returns the next element in the Enumeration.
- Throws: NoSuchElementException
- If there are no more elements
in the enumeration.
countTokens
public int countTokens()
- Returns the next number of tokens in the String using
the current deliminter set. This is the number of times
nextToken() can return before it will generate an exception.
Use of this routine to count the number of tokens is faster
than repeatedly calling nextToken() because the substrings
are not constructed and returned for each token.
All Packages Class Hierarchy This Package Previous Next Index