zoukankan      html  css  js  c++  java
  • java List<Map<String,Object>遍历的方法

    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
    ++++++++++++++++++++++++++++
       c
       b
       a
       bb
       cc
       aa
    -----------------------------
  • 相关阅读:
    Java异常
    docker安装和介绍(基于centos 7)
    centos7搭建gitlab版本控制系统
    webstorm快捷键使用
    Extjs-note
    mak iso
    windows上的硬盘挂载到linux上的步骤方法
    【JAVA笔记——术】JSP中乱码问题的解决方法
    PHP获得IP方式
    ubuntu安装hadoop 若干问题的解决
  • 原文地址:https://www.cnblogs.com/tanzq/p/8437028.html
Copyright © 2011-2022 走看看