首页 新闻 赞助 找找看

Hashtable的遍历问题!

0
悬赏园豆:100 [待解决问题]

package com.niit.www;

public class Record {

 private int id;
 private String name;
 private String telephone;
 private String remark;
 public Record(int id, String name, String telephone, String remark) {
  super();
  this.id = id;
  this.name = name;
  this.telephone = telephone;
  this.remark = remark;
 }
 public Record()
 {}
 public int getId() {
  return id;
 }
 public void setId(int id) {
  this.id = id;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public String getTelephone() {
  return telephone;
 }
 public void setTelephone(String telephone) {
  this.telephone = telephone;
 }
 public String getRemark() {
  return remark;
 }
 public void setRemark(String remark) {
  this.remark = remark;
 }
 }

 Hashtable <String,Record>hashTable=new Hashtable<String,Record>();
        Record re=new Record(1001,"jack","15165800700","chinese");
        Record re1=new Record(1002,"mike","15168421155","American");
        Record re2=new Record(1003,"rose","0154-8556","European");
        hashTable.put("1", re);
        hashTable.put("2", re1);
        hashTable.put("3", re2);

}

我想用一个for循环遍历 hashTable的 values值

用了Enunmeration  Entry KeySet都搞不定。。

谁指点下小弟啊。。。。

思想至上的主页 思想至上 | 初学一级 | 园豆:100
提问于:2011-08-04 20:08
< >
分享
所有回答(4)
0

Set<String> keys=hashTable.KeySet();
while(keys.hasNext){
Record r = hashtable.get(keys.next());
}

小-_-戴 | 园豆:9 (初学一级) | 2011-08-04 23:43
0

建议你是使用这个类型吧 IDictionary

慧☆星 | 园豆:5640 (大侠五级) | 2011-08-05 09:07
0

谁还让用HashTable这种过时的容器???

用HashMap和TreeMap还不够用吗?

知道HashTable会带来哪些问题吗?

luckygino | 园豆:205 (菜鸟二级) | 2011-08-05 21:24
不知道啊 请指教、
支持(0) 反对(0) 思想至上 | 园豆:100 (初学一级) | 2011-08-07 09:32
请教,嘻嘻~
支持(0) 反对(0) laizhd | 园豆:100 (初学一级) | 2011-08-18 16:32
0

foreach (System.Collections.DictionaryEntry de in hashTable)

{
    //注意HastTable内存储的默认类型是object,需要进行转换才可以输出
  Record rd= 
de.Value as Record; 
}

 

 

 

活在當下 | 园豆:186 (初学一级) | 2011-08-09 15:57
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册