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

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles