StringTokenizer 将一个字符串分成组件标记。
构造函数:
StringTokenizer tokens = new StringTokenizer( "this is a book" );
常用方法
tokens.countTokens() 返回tokens的数量
tokens.hasMoreTokens() 如果还有tokens返回true,否则返回false
tokens.nextToken() 获取下一个tokens
example:
// Test program for StringTokenizer
import java.io.IOException;
import java.util.StringTokenizer;
public class TokenTest {
public static void main( String args[] ) throws IOException
{
String s;
StringTokenizer st;
s = "This is a test for StringTokenizer.";
st = new StringTokenizer( s );
System.out.println( "The number of the tokens is " + st.countTokens() );
System.out.println( "The tokens are: " );
while ( st.hasMoreTokens() ) {
System.out.println( st.nextToken() );
}
}
}