arraylist里存放多个hashmap,如何读取
6个回答
展开全部
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<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map1 = new HashMap<String, Object>();
map1.put("1", "aaa");
Map<String, Object> map2 = new HashMap<String, Object>();
map2.put("2", "bbb");
Map<String, Object> map3 = new HashMap<String, Object>();
map3.put("3", "ccc");
list.add(map1);
list.add(map2);
list.add(map3);
for (Map<String, Object> map : list) {
for (Entry<String, Object> entry : map.entrySet()) {
System.out.println(entry.getKey() + " " + entry.getValue());
}
}
}
}
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<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map1 = new HashMap<String, Object>();
map1.put("1", "aaa");
Map<String, Object> map2 = new HashMap<String, Object>();
map2.put("2", "bbb");
Map<String, Object> map3 = new HashMap<String, Object>();
map3.put("3", "ccc");
list.add(map1);
list.add(map2);
list.add(map3);
for (Map<String, Object> map : list) {
for (Entry<String, Object> entry : map.entrySet()) {
System.out.println(entry.getKey() + " " + entry.getValue());
}
}
}
}
展开全部
如果你的arrayList是下面这样的
List<Map<String, Object>> listmap=new ArrayList<Map<String,Object>>();
取值可以这样取,
for (HashMap<String, Object> eachmap : listmap) {
for (Entry<String, Object> entry : eachmap.entrySet()) {
System.out.println("key:="+entry.getKey()+"; value:="+entry.getValue());
}
}
ps:手写的代码,试试把
List<Map<String, Object>> listmap=new ArrayList<Map<String,Object>>();
取值可以这样取,
for (HashMap<String, Object> eachmap : listmap) {
for (Entry<String, Object> entry : eachmap.entrySet()) {
System.out.println("key:="+entry.getKey()+"; value:="+entry.getValue());
}
}
ps:手写的代码,试试把
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
arrayList里面存hashmap,你也真够无聊的。
ArrayList<hashMap> list=new ArrayList<hashMap>();
添加元素省略
取元素:
hashMap i=(hashMap)list.get(int index);
ArrayList<hashMap> list=new ArrayList<hashMap>();
添加元素省略
取元素:
hashMap i=(hashMap)list.get(int index);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();
Map<String, String> map1 = new HashMap<String, String>();
map1.put("1", "yi");
Map<String, String> map2 = new HashMap<String, String>();
map2.put("2", "er");
Map<String, String> map3 = new HashMap<String, String>();
map3.put("3", "san");
Map<String, String> map4 = new HashMap<String, String>();
map4.put("4", "si");
list.add(map1);
list.add(map2);
list.add(map3);
list.add(map4);
Iterator<Map<String, String>> iterator = list.iterator();
while (iterator.hasNext()) {
Map<String, String> map = iterator.next();
Set<String> set = map.keySet();
Iterator<String> it = set.iterator();
while (it.hasNext()) {
String key = it.next();
System.out.println(key + "***" + map.get(key));
}
}
Map<String, String> map1 = new HashMap<String, String>();
map1.put("1", "yi");
Map<String, String> map2 = new HashMap<String, String>();
map2.put("2", "er");
Map<String, String> map3 = new HashMap<String, String>();
map3.put("3", "san");
Map<String, String> map4 = new HashMap<String, String>();
map4.put("4", "si");
list.add(map1);
list.add(map2);
list.add(map3);
list.add(map4);
Iterator<Map<String, String>> iterator = list.iterator();
while (iterator.hasNext()) {
Map<String, String> map = iterator.next();
Set<String> set = map.keySet();
Iterator<String> it = set.iterator();
while (it.hasNext()) {
String key = it.next();
System.out.println(key + "***" + map.get(key));
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
for(int i=0;i<arraylist.size();i++){
Map map =(Map)arraylist.get(i);
}
这样就可以啊
Map map =(Map)arraylist.get(i);
}
这样就可以啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询