Monday, 15 December 2014

// The "StringTokenizerExample2C" class.  Page 367 (top).
// (from the Carter book)

// Example 2C --> how to use the StringTokenizer object
// called "st3" with a String called "s", a String containing
// some white space characters (delimiters), and a boolean
// value (false) --> version # 3 of the constructor method
//
import java.util.*;
//
// The following statement:
public class StringTokenizerExample2C
{
    public static void main (String[] args)
    {
        String s = "Learning about Java constructors is\t\tHARD WORK!";
        // version # 3 of the constructor method --> writing this:
        StringTokenizer st3 = new StringTokenizer (s, " \t\n\r\f", false);
        // would have the same effect as writing this:
        StringTokenizer st4 = new StringTokenizer (s);
        // because the delimiters specified in the first constructor (above)
        // the default white space delimiters and the fact that the "flag"
        // in the first constructor (above) is set to "false" means that
        // the delimiters themselves will NOT be returned as tokens.
        //
        // to view the results of StringTokenizer object "st3":
        System.out.println ("Here is the 'st3' StringTokenizer object: ");
        // while (st3.hasMoreTokens())
        // {
        //      System.out.println (st3.nextToken());
        // }
        System.out.println ();
        // to view the results of StringTokenizer object "st4":
        System.out.println ("Here is the 'st4' StringTokenizer object: ");
        while (st4.hasMoreTokens ())
        {
            System.out.println (st4.nextToken ());

        } // end of while loop

    } // main method
} // StringTokenizerExample2C class

No comments:

Post a Comment