如何在android中循环使用HashTable键?

use*_*801 4 android

我有一个填充数据的哈希表,但我不知道密钥如何通过android中的HashTable键循环?我正在尝试这个,但它不起作用:

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));
}
Run Code Online (Sandbox Code Playgroud)

ido*_*dok 9

使用枚举遍历表中的所有值.可能这是你想要做的:

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