Facebook Page Twitter Page LinkedIn Page
× Java Utility Library


Java StringTokenizer Class

Java.util package provides a StringTokenizer class which allows an application to break a string into tokens. This class is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. Its methods do not distinguish among identifiers, numbers, and quoted strings. This class methods do not even recognize and skip comments.

Class declaration

The declaration of java.util.StringTokenizer class is:

public class StringTokenizer
  extends Object
    implements Enumeration<Object>

Class Constructors

S.NConstructors & Description
1. StringTokenizer(String str)
Constructs a string tokenizer for the specified string.
2. StringTokenizer(String str, String delim)
Constructs a string tokenizer for the specified string.
3. StringTokenizer(String str, String delim, boolean returnDelims)
Constructs a string tokenizer for the specified string.

java.util.StringTokenizer Methods

The java.util.StringTokenizer class has a number of methods which are listed below:

Member Methods

S.NMethods & Description
1. int countTokens()
Calculates the number of times that this tokenizer's nextToken method can be called before it generates an exception.
2. boolean hasMoreElements()
Returns the same value as the hasMoreTokens method.
3. boolean hasMoreTokens()
Tests if there are more tokens available from this tokenizer's string.
4. Object nextElement()
Returns the same value as the nextToken method, except that its declared return value is Object rather than String.
5. String nextToken()
Returns the next token from this string tokenizer.
6. String nextToken(String delim)
Returns the next token in this string tokenizer's string.

Methods inherited

This class inherits the methods of following class:

  • java.lang.Object

5