java enumeration 创建_一个java Enumeration类型的使用方法

package ibm; import java.util.*; class PrintData{ static void print(Enumeration e){   while(e.hasMoreElements()){     System.out.println(e.nextElement().toString());//toString方法重载过   } } } class Mouse{ int mouseNumber;   Mouse(int i){ this.mouseNumber=i;}   public  String toString(){     return "this is a mouse "+mouseNumber; } } class Hasmeter{ int hasNumber;   Hasmeter(int i){ this.hasNumber=i;}   public  String toString(){     return "this is a hasmeter "+hasNumber; } } public class HashTest2 {   public static void main(String[] args) {     HashTest2 hashtest2 = new HashTest2();     Vector vc=new Vector();     for (int i=0;i<5;i++) {vc.addElement(new Mouse(i));}     Hashtable ht=new Hashtable();     for (int i=0;i<5;i++){ht.put(new Integer(i),new Hasmeter(i));}//放入堆     if(ht.containsKey(3)){System.out.println(ht.get(3));}     System.out.print(ht+"\n");     PrintData.print(vc.elements());     PrintData.print(ht.elements());        } } 结果如下: this is a hasmeter 3 {4=this is a hasmeter 4, 3=this is a hasmeter 3, 2=this is a hasmeter 2, 1=this is a hasmeter 1, 0=this is a hasmeter 0} this is a mouse 0 this is a mouse 1 this is a mouse 2 this is a mouse 3 this is a mouse 4 this is a hasmeter 4 this is a hasmeter 3 this is a hasmeter 2 this is a hasmeter 1 this is a hasmeter 0   package ibm; import java.util.*; public class IreratorTest {   public static void main(String[] args) {     IreratorTest ireratortest = new IreratorTest();     Collection c=new ArrayList();     for(int i=1;i<=100;i++){     c.add(Integer.toString(i));     }     Iterator it=c.iterator();     while(it.hasNext()){     System.out.println(it.next());     }   } }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值