SunSPOT API V5.0


com.sun.squawk.util
Class StringTokenizer

java.lang.Object
  extended by com.sun.squawk.util.StringTokenizer
All Implemented Interfaces:
Enumeration

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
 

Version:
1.13, 10 Aug 1995

Constructor Summary
StringTokenizer(String str)
          Constructs a StringTokenizer on the specified String, using the default delimiter set (which is " \t\n\r").
StringTokenizer(String str, String delim)
          Constructs a StringTokenizer on the specified String, using the specified delimiter set.
StringTokenizer(String str, String delim, boolean returnTokens)
          Constructs a StringTokenizer on the specified String, using the specified delimiter set.
 
Method Summary
 int countTokens()
          Returns the next number of tokens in the String using the current deliminter set.
 boolean hasMoreElements()
          Returns true if the Enumeration has more elements.
 boolean hasMoreTokens()
          Returns true if more tokens exist.
 Object nextElement()
          Returns the next element in the Enumeration.
 String nextToken()
          Returns the next token of the String.
 String nextToken(String delim)
          Returns the next token, after switching to the new delimiter set.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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

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,
                       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
Method Detail

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.


hasMoreElements

public boolean hasMoreElements()
Returns true if the Enumeration has more elements.

Specified by:
hasMoreElements in interface Enumeration
Returns:
true if and only if this enumeration object contains at least one more element to provide; false otherwise.

hasMoreTokens

public boolean hasMoreTokens()
Returns true if more tokens exist.


nextElement

public Object nextElement()
Returns the next element in the Enumeration.

Specified by:
nextElement in interface Enumeration
Returns:
the next element of this enumeration.
Throws:
NoSuchElementException - If there are no more elements in the enumeration.

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

SunSPOT API V5.0


Copyright � 2006-2008 Sun Microsystems, Inc. All Rights Reserved.