打包测试;
import Java.util.string tokenizer;
publicclassstringtokenizertest {
//*
* @param args
*/
publicstaticvoidmain (字符串[ ] args ) {
String s='I am zhangwuji,she is my friends ';
stringtokenizerfx=new string tokenizer (s,','; //分别使用空格逗号作为分隔符
int number=fx.countTokens (;
while(FX.hasmoretokens () ) ) )。
String str=fx.nextToken (;
System.out.println (当前单词: ' str );
System.out.println ('剩下' fx.countTokens ) ) '单词');
}
System.out.println (共享单词“number”个);
}
私密性统计数据缓冲器{
如果未在//java中指定分隔符,则默认值为空格
string str=' this is a Java程序';
stringtokenizerst=new string tokenizer (str;
while(ST.hasmoretokens () ) )。
system.out.println (ST.next token ) );
}
system.out.println (' * * * * * * * * * * * * * * * * * * * * * * * * ' );
//st.hasMoreElements用法作用相同,只能写一个,st被调用后到达分割末尾
//while(ST.hasmoreelements () ) }
//system.out.println (ST.nextelement ) );
//}
}
}