by Dinesh Thakur Category: Stream

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

import java.util.StringTokenizer;

class JavaStringTokenizerExample
     public static void main(String args[]) throws IOException
              BufferedReader k = new BufferedReader(new InputStreamReader(;
              int n;
                 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())
             }  while(n !=0);

Java StringTokenizer example

Popular Article