我怎么能循环thorugth在Android的一个哈希表的键? [英] How can i loop thorugth a HashTable keys in android?

查看:195
本文介绍了我怎么能循环thorugth在Android的一个哈希表的键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我充满了数据的哈希表,但我不知道钥匙
我怎样才能循环througth在Android的一个哈希表的键?
我想这一点,但它不工作:

  Hashtable的输出=新的Hashtable();
output.put(POS1,1);
output.put(POS2,2);
output.put(POS3,3);
ArrayList的<串GT; mykeys =(ArrayList的<串GT;)output.keys();
的for(int i = 0; I< mykeys.size();我++){
   txt.append(\\ n+ mykeys.get(I));
}


解决方案

使用枚举遍历在所有的值在表中。
也许这是你想要做什么:

 枚举E = output.keys();
而(e.hasMoreElements()){
    整数i =(整数)e.nextElement();
    txt.append(\\ n+ output.get(I));
}

I have a hashtable filled with data, but I don't know the keys How can I loop througth a HashTable keys in android? I'm trying this, but it doesnt work:

Hashtable output=new Hashtable();
output.put("pos1","1");
output.put("pos2","2");
output.put("pos3","3");


ArrayList<String> mykeys=(ArrayList<String>)output.keys();
for (int i=0;i< mykeys.size();i++){             
   txt.append("\n"+mykeys.get(i));
}

解决方案

Use enumeration to traverse over all the values in the table. Probably this is what you would want to do:

Enumeration e = output.keys();
while (e.hasMoreElements()) {
    Integer i = (Integer) e.nextElement();
    txt.append("\n"+output.get(i));
}

这篇关于我怎么能循环thorugth在Android的一个哈希表的键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆