class StringTokenizer
Object to: break a string into tokens.
Contructs
StringTokenizer(String str) Constructs a string tokenizer for the specified string. |
StringTokenizer(String str, String delim) Constructs a string tokenizer for the specified string. |
StringTokenizer(String str, String delim, boolean returnDelims) Constructs a string tokenizer for the specified string. |
Example 1: withdout delimiter characters
StringTokenizer st = new StringTokenizer("Hello World of Java"); while (st.hasMoreTokens()) System.out.println("Token: " + st.nextToken());
Example 2: with delimiter characters
StringTokenizer st = new StringTokenizer("Hello, World|of|Java", ", |"); while (st.hasMoreElements()) System.out.println("Token: " + st.nextElement());
其中,分隔符为','或者'|'。