Java's StringTokenizer class:

  1. Java's library contains a very useful StringTokenizer class used for text processing: click here

  2. Creating StringTokenizer objects:

    Example creating a StringTokenizer object with string "I love my pet dinosaur":
          StringTokenizer x = new StringTokenizer("I love my pet dinosaur");
    

    Result:

  3. Instance methods in StringTokenizer:

  4. Example:

    Example using StringTokenizer
          StringTokenizer x = new StringTokenizer("I love my pet dinosaur");
          String s;
    
          s = x.nextToken();   // s = "I"
          s = x.nextToken();   // s = "love"
          s = x.nextToken();   // s = "my"
          s = x.nextToken();   // s = "pet"
          s = x.nextToken();   // s = "dinosaur"
          s = x.nextToken();   // error !
    

  5. A more realistic example:

    Processing words in a sentence:
          StringTokenizer x = new StringTokenizer("I love my pet dinosaur");
          String s;
    
          while ( x.hasMoreTokens() )
          {  
             s = x.nextToken();
             Process word s
          } 
    

    DEMO program: click here
    (Demo pipe !)