// (from the Carter book)
// Example 2B --> how to use the StringTokenizer object (called "st2")
// (using the version # 2 constructor method)
//
import java.util.*;
//
// The following statement:
public class StringTokenizerExample2B
{
public static void main (String[] args)
{
// this is the version # 2 constructor method:
StringTokenizer st2 = new StringTokenizer ("http://www.java.sun.com", ":/.");
// would create a StringTokenizer object ("st2")
// with the following tokens (not including delimiters):
//
// "http"
// "www"
// "java"
// "sun"
// "com"
//
// To view the contents of "st2", use a while loop, as follows:
while (st2.hasMoreTokens ())
{
System.out.println (st2.nextToken ());
} // end of while loop
} // main method
} // StringTokenizerExample2B class
No comments:
Post a Comment