码迷,mamicode.com
首页 > 编程语言 > 详细

java List<Map<String,Object>遍历的方法

时间:2019-01-02 15:03:02      阅读:809      评论:0      收藏:0      [点我收藏+]

标签:next   图片   复制   size   val   div   代码   asn   try   

技术分享图片
public class Test {
    public static void main(String[] args) {

        List<Map<String, Object>> listMaps = new ArrayList<Map<String, Object>>();
        
        Map<String, Object> map1 = new HashMap<String, Object>();
        map1.put("1", "a");
        map1.put("2", "b");
        map1.put("3", "c");
        listMaps.add(map1);

        Map<String, Object> map2 = new HashMap<String, Object>();
        map2.put("11", "aa");
        map2.put("22", "bb");
        map2.put("33", "cc");
        listMaps.add(map2);

        for (Map<String, Object> map : listMaps) {
            for (String s : map.keySet()) {
                System.out.print(map.get(s) + "  ");
            }
        }
        System.out.println();
        System.out.println("========================");
        for (int i = 0; i < listMaps.size(); i++) {
            Map<String, Object> map = listMaps.get(i);
            Iterator iterator = map.keySet().iterator();
            while (iterator.hasNext()) {
                String string = (String) iterator.next();
                System.out.println(map.get(string));
            }
        }
        System.out.println("++++++++++++++++++++++++++++");
        for (Map<String, Object> map : listMaps) {
            for (Map.Entry<String, Object> m : map.entrySet()) {
                System.out.print(m.getKey() + "    ");
                System.out.println(m.getValue());
            }
        }
        System.out.println("-----------------------------");
    }

}


打印的结果:

c  b  a  bb  cc  aa  
========================
c
b
a
bb
cc
aa
++++++++++++++++++++++++++++
3    c
2    b
1    a
22    bb
33    cc
11    aa
-----------------------------

java List<Map<String,Object>遍历的方法

标签:next   图片   复制   size   val   div   代码   asn   try   

原文地址:https://www.cnblogs.com/Yusco/p/10208178.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
分享档案
周排行
mamicode.com排行更多图片
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!