Chinaunix首页 | 论坛 | 博客

-

  • 博客访问: 165275
  • 博文数量: 48
  • 博客积分: 2000
  • 博客等级: 大尉
  • 技术积分: 490
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-22 18:51
文章分类

全部博文(48)

文章存档

2010年(23)

2009年(25)

我的朋友

分类: 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();
 }
}

 
 
阅读(1246) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~