map<string,object>怎么遍历
2个回答
2020-02-16
展开全部
通过map.entrySet()转成Set 再遍历。上面的方法是加入list集合再遍历
Set<Map.Entry<String, Object>> entries = map.entrySet();
for (Map.Entry<String, Object> entry:entries) {
System.out.println("entry.getKey()----"+entry.getKey()+"======entry.getValue()----"+entry.getValue());
}
Set<Map.Entry<String, Object>> entries = map.entrySet();
for (Map.Entry<String, Object> entry:entries) {
System.out.println("entry.getKey()----"+entry.getKey()+"======entry.getValue()----"+entry.getValue());
}
展开全部
示例如下:
Map<String,Object> map = new HashMap<String, String>(); map.put("1", "fds"); map.put("2", "valu"); List<Map<String, String>> list = new ArrayList<Map<String, String>>(); list.add(map); for (Map<String, String> m : list) { for (String k : m.keySet()) { System.out.println(k + " : " + m.get(k)); } }
Map<String,Object> map = new HashMap<String, String>(); map.put("1", "fds"); map.put("2", "valu"); List<Map<String, String>> list = new ArrayList<Map<String, String>>(); list.add(map); for (Map<String, String> m : list) { for (String k : m.keySet()) { System.out.println(k + " : " + m.get(k)); } }
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询