jdk源码详解之StringTokenizer
1.类释义
The string tokenizer class allows an application to break a string into tokens
2.
3.类方法
3.1 hasMoreTokens()
译:判断在这个tokenizer 字符串中是否有更多可用的tokens。如果这个方法返回 true,那么后续对无参的nextToken()【nextToken()方法分两种,分别是有参和无参的】的调用将会成功返回一个token。
3.2 nextToken()
3.3 StringTokenizer()
public StringTokenizer(String str)
Constructs a string tokenizer for the specified string. The tokenizer uses the default delimiter set, which is " \t\n\r\f": the space character, the tab character, the newline character, the carriage-return character, and the form-feed character. Delimiter characters themselves will not be treated as tokens.
Parameters:
str - a string to be parsed.
Throws:
NullPointerException - if str is null
注意默认的分隔符是哪几个。空格,tab,换行符,回车符,换页符
4.简单示例
4.1
package test;
import java.util.StringTokenizer;
public class TestStringTokenizer {
public static void main(String args[]) {
StringTokenizer st = new StringTokenizer("this is a test");
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}
}
}