arraylist里存放多个hashmap,如何读取

arraylist里存放多个hashmap,如何读取

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class Test {
public static void main(String[] args) {
List> list = new ArrayList>();
Map map1 = new HashMap();
map1.put("1", "aaa");
Map map2 = new HashMap();
map2.put("物禅2", "bbb");
Map<敏毁String, Object> map3 = new HashMap();
map3.put("3", "ccc");
list.add(map1);
list.add(map2);
list.add(map3);
for (Map桥蚂备 map : list) {
for (Entry entry : map.entrySet()) {
System.out.println(entry.getKey() + " " + entry.getValue());
}
}
}
}
如果你的arrayList是下面这样的
List> listmap=new ArrayList>();

取羡镇源值可以这样取,
for (HashMap eachmap : listmap) {
for (Entry entry : eachmap.entrySet()) {
System.out.println("兄态key:="+entry.getKey()+"; value:="+entry.getValue());
}
}
ps:手写的代码,试试把
arrayList里面存hashmap,袜链段唤举你也真够无聊的。
ArrayList list=new ArrayList();
添加元素省略告誉
取元素:
hashMap i=(hashMap)list.get(int index);
ArrayList> list = new ArrayList>();
Map map1 = new HashMap();
map1.put("1", "yi"岁皮兄);
Map map2 = new HashMap();
map2.put("2", "er");
Map map3 = new HashMap();
map3.put("3", "san");
Map map4 = new HashMap<握冲String, String>();
map4.put("4", "si");

list.add(map1);
list.add(map2);
list.add(map3);
list.add(map4);

Iterator> iterator = list.iterator();
while (iterator.hasNext()) {
Map map = iterator.next();
Set乎袭 set = map.keySet();
Iterator it = set.iterator();
while (it.hasNext()) {
String key = it.next();
System.out.println(key + "***" + map.get(key));
}
}
for(int i=0;iMap map =(Map)arraylist.get(i);

}
这样燃盯好就可以皮铅啊则茄
← 上一篇: 下一篇: →