StringTokenizer in Java

StringTokenizer allows you to specify a delimiter as a set of characters and matches any number or combination of those characters as a delimiter between tokens. The following code snippet reads the words:

    String str = "Java is object oriented language”;

    StringTokenizer st = new StringTokenizer(str);

    while (st.hasMoreTokens())
               {
               String word = st.nextToken();
               ...
               }

We invoke the hasMoreTokens( ) and nextToken( ) methods to loop over the words of the text. By default, the StringTokenizer class uses standard whitespace characterscarriage return, newline, and tabas delimiters. You can also specify your own set of delimiter characters in the StringTokenizer constructor. Any contiguous combination of the specified characters that appears in the target string is skipped between tokens:

Example:

import java.util.StringTokenizer;

/**
 *
 * @author JavaHotSpot
 */

public class StringTonenizers
{
  public static void main(String args[])
  {
      String str = "Apple,Orange,Banana,Mango,pinaple";
      StringTokenizer st;
      st=new StringTokenizer(str,",");
      while(st.hasMoreTokens())
      {
          System.out.println(st.nextToken());
      }
  }
}

Output:
Apple
Orange
Banana
Mango