12 8 5 32
4 tokens, delimited by spaces.
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:
The countTokens()
method will start 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 the tiny program, expanded to use two of these methods.
import java.util.* ; public class TokenTester { public static void main ( String[] args ) { StringTokenizer tok; if ( args.length > 0 ) { tok = new StringTokenizer( args[0] ); while ( tok.hasMoreTokens() ) System.out.println( tok.nextToken() ); } } }