Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

java.util
Class StringTokenizer  view StringTokenizer download StringTokenizer.java

java.lang.Object
  extended byjava.util.StringTokenizer
All Implemented Interfaces:
Enumeration

public class StringTokenizer
extends java.lang.Object
implements Enumeration

This class splits a string into tokens. The caller can set on which delimiters the string should be split and if the delimiters should be returned. This is much simpler than java.io.StreamTokenizer.

You may change the delimiter set on the fly by calling nextToken(String). But the semantic is quite difficult; it even depends on calling hasMoreTokens(). You should call hasMoreTokens() before, otherwise the old delimiters after the last token are candidates for being returned.

If you want to get the delimiters, you have to use the three argument constructor. The delimiters are returned as token consisting of a single character.


Field Summary
private  java.lang.String delim
          The string containing the delimiter characters.
private  int len
          The length of the string.
private  int pos
          The position in the str, where we currently are.
private  boolean retDelims
          Tells, if we should return the delimiters.
private  java.lang.String str
          The string that should be split into tokens.
 
Constructor Summary
StringTokenizer(java.lang.String str)
          Creates a new StringTokenizer for the string str, that should split on the default delimiter set (space, tab, newline, return and formfeed), and which doesn't return the delimiters.
StringTokenizer(java.lang.String str, java.lang.String delim)
          Create a new StringTokenizer, that splits the given string on the given delimiter characters.
StringTokenizer(java.lang.String str, java.lang.String delim, boolean returnDelims)
          Create a new StringTokenizer, that splits the given string on the given delimiter characters.
 
Method Summary
 int countTokens()
          This counts the number of remaining tokens in the string, with respect to the current delimiter set.
 boolean hasMoreElements()
          This does the same as hasMoreTokens.
 boolean hasMoreTokens()
          Tells if there are more tokens.
 java.lang.Object nextElement()
          This does the same as nextTokens.
 java.lang.String nextToken()
          Returns the nextToken of the string.
 java.lang.String nextToken(java.lang.String delim)
          Returns the nextToken, changing the delimiter set to the given delim.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pos

private int pos
The position in the str, where we currently are.


str

private final java.lang.String str
The string that should be split into tokens.


len

private final int len
The length of the string.


delim

private java.lang.String delim
The string containing the delimiter characters.


retDelims

private final boolean retDelims
Tells, if we should return the delimiters.

Constructor Detail

StringTokenizer

public StringTokenizer(java.lang.String str)
Creates a new StringTokenizer for the string str, that should split on the default delimiter set (space, tab, newline, return and formfeed), and which doesn't return the delimiters.


StringTokenizer

public StringTokenizer(java.lang.String str,
                       java.lang.String delim)
Create a new StringTokenizer, that splits the given string on the given delimiter characters. It doesn't return the delimiter characters.


StringTokenizer

public StringTokenizer(java.lang.String str,
                       java.lang.String delim,
                       boolean returnDelims)
Create a new StringTokenizer, that splits the given string on the given delimiter characters. If you set returnDelims to true, the delimiter characters are returned as tokens of their own. The delimiter tokens always consist of a single character.

Method Detail

hasMoreTokens

public boolean hasMoreTokens()
Tells if there are more tokens.


nextToken

public java.lang.String nextToken(java.lang.String delim)
                           throws NoSuchElementException
Returns the nextToken, changing the delimiter set to the given delim. The change of the delimiter set is permanent, ie. the next call of nextToken(), uses the same delimiter set.


nextToken

public java.lang.String nextToken()
                           throws NoSuchElementException
Returns the nextToken of the string.


hasMoreElements

public boolean hasMoreElements()
This does the same as hasMoreTokens. This is the Enumeration interface method.

Specified by:
hasMoreElements in interface Enumeration

nextElement

public java.lang.Object nextElement()
                             throws NoSuchElementException
This does the same as nextTokens. This is the Enumeration interface method.

Specified by:
nextElement in interface Enumeration

countTokens

public int countTokens()
This counts the number of remaining tokens in the string, with respect to the current delimiter set.