java 如何迭代 Arraylist<HashMap<String,String>>?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7683960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to iterate Arraylist<HashMap<String,String>>?
提问by Piyush
I have an ArrayList object like this:
我有一个像这样的 ArrayList 对象:
ArrayList<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
How to iterate through the list? I want to display the value in a TextView which comes from the data of ArrayList object.
如何遍历列表?我想在来自 ArrayList 对象数据的 TextView 中显示值。
回答by dacwe
Simplest is to iterate over all the HashMap
s in the ArrayList
and then iterate over all the keys in the Map
:
最简单的方法是遍历 中的所有HashMap
s ArrayList
,然后遍历 中的所有键Map
:
TextView view = (TextView) view.findViewById(R.id.view);
for (HashMap<String, String> map : data)
for (Entry<String, String> entry : map.entrySet())
view.append(entry.getKey() + " => " + entry.getValue());
回答by DallinDyer
for(HashMap<String, String> map : data){
... deal with map...
}
for(HashMap<String, String> map : data){
... deal with map...
}