Class java.util.StringTokenizer
All Packages This Package Previous Next
Class java.util.StringTokenizer
java.lang.Object
|
+----java.util.StringTokenizer
-
public class
StringTokenizer
-
extends Object
-
implements Enumeration
A class to tokenize a string.
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
-
Version:
-
1.8, 31 Jan 1995
-
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").
-
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)
-
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").
hasMoreTokens
public boolean hasMoreTokens()
-
Returns true if more tokens exist.
nextToken
public String nextToken()
-
Returns the next token of the string.
-
Throws: NoSuchElementException
-
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
-
There are no more elements in the enumeration
All Packages This Package Previous Next