Topic: 请写出Hashtable类中遍历所有值的方法(谢谢!)

  Print this page

1.请写出Hashtable类中遍历所有值的方法(谢谢!) Copy to clipboard
Posted by: redeyelove
Posted on: 2006-07-18 19:26

请写出Hashtable类中遍历所有值的方法
Hashtable hash = new Hashtable();

2.Re:请写出Hashtable类中遍历所有值的方法(谢谢!) [Re: redeyelove] Copy to clipboard
Posted by: Freax
Posted on: 2006-07-19 09:19


   Hashtable ht = new Hashtable();
    ht.put("one",new Integer(1));
    ht.put("two",new Integer(2));
    Enumeration en = ht.elements();
    while(en.hasMoreElements()){
   System.out.println((Integer)en.nextElement());
    }

or
                 
  Set s = ht.entrySet();
   for (Object o:s.toArray()){
System.out.println(o);
   }
      //only java 5.0
//print one=1 two=2
    }


about more , see java.util.Enumeration and java.util.Hashtable

3.Re:请写出Hashtable类中遍历所有值的方法(谢谢!) [Re: redeyelove] Copy to clipboard
Posted by: sunjavaduke
Posted on: 2006-07-19 12:15

Hashtable is an old class.
suggest not use it~

4.Re:请写出Hashtable类中遍历所有值的方法(谢谢!) [Re: redeyelove] Copy to clipboard
Posted by: tomcatexpert
Posted on: 2006-07-21 16:00

楼上的,请教一下,为什么不建议使用hashtable?
更“新”的collection又是什么?

5.Re:请写出Hashtable类中遍历所有值的方法(谢谢!) [Re: redeyelove] Copy to clipboard
Posted by: why
Posted on: 2006-07-21 18:13

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Hashtable.html :
As of the Java 2 platform v1.2, this class has been retrofitted to implement Map, so that it becomes a part of Java's collection framework. Unlike the new collection implementations, Hashtable is synchronized.

6.Re:请写出Hashtable类中遍历所有值的方法(谢谢!) [Re: redeyelove] Copy to clipboard
Posted by: ranchgirl
Posted on: 2006-07-22 21:48

请写出Hashtable类中遍历所有值的方法
Hashtable hash = new Hashtable();


System.println(hash);


This is because Hashtable or HashMap has overrode the toString() method.


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923