Use StringTokenizer to break string value and count tokens - Java Language Basics

Java examples for Language Basics:StringTokenizer

Description

Use StringTokenizer to break string value and count tokens

Demo Code


import java.util.StringTokenizer;
 
public class Main {
 
  public static void main(String[] args) {
    StringTokenizer st = new StringTokenizer("Java StringTokenizer count Tokens Example");
    while(st.hasMoreTokens()){
      System.out.println("Remaining Tokens : " + st.countTokens());
      System.out.println(st.nextToken());
    }//from   www.  j  a v  a  2  s  . co  m
   
  }
}

Result


Related Tutorials