1:import java.util.*; 2:/** 3: * This class demonstrates how to use the StringTokenizer class to splitt apart 4: * strings of text. 5: */ 6:class SplitString { 7: 8: public static void main(String[] arguments) { 9: StringTokenizer ex1, ex2; // Declare StringTokenizer Objects 10: int count = 0; 11: 12: String strOne = "one two three four five"; 13: ex1 = new StringTokenizer(strOne); //Split on Space (default) 14: 15: while (ex1.hasMoreTokens()) { 16: count++; 17: System.out.println("Token " + count + " is [" + ex1.nextToken() + "]"); 18: } 19: 20: count = 0; // Reset counter 21: 22: String strTwo = "item one,item two,item three,item four"; // Comma Separated 23: ex2 = new StringTokenizer(strTwo, ","); //Split on comma 24: 25: while (ex2.hasMoreTokens()) { 26: count++; 27: System.out.println("Token " + count + " is [" + ex2.nextToken() + "]"); 28: } 29: } 30:}