分类: Java
2009-11-02 17:21:52
import java.util.StringTokenizer;
public class StringTokenizerTest {
public static void see(String str){
System.out.println(str);
}
public static void see(int intValue){
System.out.println(intValue);
}
public static void test(){
StringTokenizer st1=new StringTokenizer("this is a test method.");
while(st1.hasMoreTokens()){
System.out.println(st1.nextToken());
}
StringTokenizer st2=new StringTokenizer("this is a test method"," ");
while(st2.hasMoreTokens()){
see(st2.nextToken());
}
StringTokenizer st3=new StringTokenizer("this/is/a/test/meths","/");
while(st3.hasMoreTokens()){
see(st3.nextToken());
}
StringTokenizer st4=new StringTokenizer("this/is/a/StringTokenizer/object","/",false);
while(st4.hasMoreTokens()){
see(st4.nextToken());
}
StringTokenizer st5=new StringTokenizer("this/is/a/StringTokenizer/object","/",true);
while(st5.hasMoreTokens()){
see(st5.nextToken());
}
StringTokenizer st6=new StringTokenizer("this/is/a/test/meths","/");
see(st6.countTokens());
StringTokenizer st7=new StringTokenizer("this/is/a/test/meths","/");
while(st7.hasMoreElements()){
String str=(String) st7.nextElement();
see(str);
}
StringTokenizer st=new StringTokenizer("this/is/a/test/method","/");
while(st.hasMoreElements()){
// see(st.nextToken("/"));
see(st.nextToken("s"));
// see(st.nextToken());
}
}
public static void main(String[] args) {
test();
}
}