by Dinesh Thakur

java.util.StringTokenizer class split String into different token by “space” and “comma” delimiter.

import java.util.StringTokenizer;

import java.io.*;
class JavaStringTokenizerExample
{
     public static void main(String args[]) throws IOException
      {
              BufferedReader k = new BufferedReader(new InputStreamReader(System.in));
              int n;
             do
            {
                 System.out.println("Enter a string,Enter to quit");
                 StringTokenizer h = new StringTokenizer(k.readLine());
                 n = h.countTokens();
                 System.out.println("There are "+n+" tokens");
                 while (h.hasMoreTokens())
                 System.out.println(h.nextToken());                        
             }  while(n !=0);
      }
}

Java StringTokenizer example