12  8  5  32

A good answer might be:

4 tokens, delimited by spaces.


More than one Delimiter Works

Tokens can be separated by more than one delimiter. There are several spaces separating the tokens in the example. Here are some methods of the class:

StringTokenizer Methods
int countTokens() return the number of tokens remaining.
boolean hasMoreTokens() return true if there are more tokens.
String nextToken() return the next token.

The countTokens() method starts with the total number of tokens the String has been broken into. Each time nextToken() is called, one token (starting with the first) is consumed, and countTokens() will report one less token. Here is an example program:

import java.io.*;
import java.util.*;

public class TokenTester
{
  public static void main ( String[] args ) throws IOException
  {
    BufferedReader stdin = 
      new BufferedReader(new InputStreamReader(System.in));

    System.out.print("Enter a string:");
    String data = stdin.readLine();   
    
    StringTokenizer tok = new StringTokenizer( data );

    while ( tok.hasMoreTokens() )
      System.out.println( tok.nextToken() );
  }
}

QUESTION 15:

What will the output be for the following:

C:\> java TokenTester
Enter a string: 12  8  5  32