How to iterate Arraylist>?

2020-02-08 20:57发布

I have an ArrayList object like this:

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.

2条回答
看我几分像从前
2楼-- · 2020-02-08 21:34

Simplest is to iterate over all the HashMaps in the ArrayList and then iterate over all the keys in the 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());
查看更多
来,给爷笑一个
3楼-- · 2020-02-08 21:38

for(HashMap<String, String> map : data){ ... deal with map... }

查看更多
登录 后发表回答