arraylist里存放多个hashmap,如何读取?
1个回答
展开全部
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());
}
}
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询