Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i loop thorugth a HashTable keys in android?

Tags:

android

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));
}
like image 794
user467801 Avatar asked Dec 16 '22 21:12

user467801


1 Answers

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));
}
like image 136
idok Avatar answered Dec 26 '22 13:12

idok