This documentation is archived and is not being maintained.

StringTokenizer Class

Visual Studio 2005

Provides methods to parse a string and split it into tokens based on a delimiter.

Package: java.util

Assembly: vjslib (in vjslib.dll)


public class java.util.StringTokenizer
    extends java.lang.Object
    implements java.util.Enumeration

The following example demonstrates the countTokens, hasMoreElements, hasMoreTokens, nextElement, and nextToken methods of the StringTokenizer class.

// stringtokenizer_overview.jsl

import java.util.*;

public class Program
{
    public static void main(String[] args)
    {
        String str =
            "This is/some text/that I am/parsing/using StringTokenizer/.";

        StringTokenizer strTokElem =
            new StringTokenizer(str, "/", true);
        System.out.println("Elements...");
        while (strTokElem.hasMoreElements())
        {
            System.out.println(strTokElem.nextElement());
        }

        StringTokenizer strTokToken =
            new StringTokenizer(str, "/", false);
        System.out.println("Tokens...");
        while (strTokToken.hasMoreTokens())
        {
            System.out.println(strTokToken.nextToken());
        }

        StringTokenizer strTok =
            new StringTokenizer(str, "/", false);
        System.out.println("Count...");
        System.out.println(strTok.countTokens());
    }
}

/*
Output:
Elements...
This is
/
some text
/
that I am
/
parsing
/
using StringTokenizer
/
.
Tokens...
This is
some text
that I am
parsing
using StringTokenizer
.
Count...
6
*/

java.lang.Object

  java.util.StringTokenizer

Show: