All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object
|
+----java.util.StringTokenizer
StreamTokenizer
class. The
StringTokenizer
methods do not distinguish among
identifiers, numbers, and quoted strings, nor do they recognize
and skip comments.
The set of delimiters (the characters that separate tokens) may be specified either at creation time or on a per-token basis.
An instance of StringTokenizer
behaves in one of two
ways, depending on whether it was created with the
returnTokens
flag having the value true
or false
:
false
, delimiter characters serve to
separate tokens. A token is a maximal sequence of consecutive
characters that are not delimiters.
true
, delimiter characters are considered to
be tokens. A token is either one delimiter character, or a maximal
sequence of consecutive characters that are not delimiters.
The following is one example of the use of the tokenizer. The code:
StringTokenizer st = new StringTokenizer("this is a test");
while (st.hasMoreTokens()) {
println(st.nextToken());
}
prints the following output:
this
is
a
test
nextToken
method can be called before it generates an
exception.
hasMoreTokens
method.
nextToken
method,
except that its declared return value is Object
rather than
String
.
public StringTokenizer(String str,
String delim,
boolean returnTokens)
delim
argument are the delimiters
for separating tokens.
If the returnTokens
flag is true
, then
the delimiter characters are also returned as tokens. Each
delimiter is returned as a string of length one. If the flag is
false
, the delimiter characters are skipped and only
serve as separators between tokens.
public StringTokenizer(String str,
String delim)
delim
argument are the delimiters
for separating tokens.
public StringTokenizer(String str)
"\t\n\r"
: the space character, the tab
character, the newline character, and the carriage-return character.
public boolean hasMoreTokens()
true
if there are more tokens available from this
tokenizer's string; false
otherwise.
public String nextToken()
public String nextToken(String delim)
public boolean hasMoreElements()
hasMoreTokens
method. It exists so that this class can implement the
Enumeration
interface.
true
if there are more tokens;
false
otherwise.
public Object nextElement()
nextToken
method,
except that its declared return value is Object
rather than
String
. It exists so that this class can implement the
Enumeration
interface.
public int countTokens()
nextToken
method can be called before it generates an
exception.
All Packages Class Hierarchy This Package Previous Next Index