8.1 The StringTokenizer class 

Previous Index Next 


The StringTokenizer class is found in the java.util package. This class takes a string and breaks it up into tokens. The class allows the set of delimiters to be defined when it is created.

For example the following code:

String testString = "This is a,test";

StringTokenizer tokenizer = new StringTokenizer( testString," ," ); // delimiters are space and comma
while ( tokenizer.hasMoreTokens() )
  {
   System.out.println( tokenizer.nextToken() );
  }
produces the following output:
this
is
a
test


Source 1