list中存放map实例

list中存放map实例

List中存放Map遍历输出的实例

 

  1.  
    import java.util.ArrayList;
  2.  
    import java.util.HashMap;
  3.  
    import java.util.Iterator;
  4.  
    import java.util.List;
  5.  
    import java.util.Map;
  6.  
     
  7.  
    public class ListMap {
  8.  
     
  9.  
    static List<Map> lis = new ArrayList<Map>();
  10.  
    static Map<Integer, String> map = new HashMap<Integer, String>();
  11.  
    static Map<Integer, Integer> ma = new HashMap<Integer, Integer>();
  12.  
     
  13.  
    public static void main(String[] args) {
  14.  
     
  15.  
    map.put(1, "aaa");
  16.  
    map.put(2, "bbb");
  17.  
    map.put(3, "ccc");
  18.  
     
  19.  
    ma.put(1, 1);
  20.  
    ma.put(2, 2);
  21.  
    ma.put(3, 3);
  22.  
     
  23.  
    lis.add(map);
  24.  
    lis.add(ma);
  25.  
     
  26.  
    for (Map m : lis) {
  27.  
    Iterator<Map.Entry<Object, Object>> it = m.entrySet().iterator();
  28.  
    while (it.hasNext()) {
  29.  
    Map.Entry<Object, Object> entry = it.next();
  30.  
    System.out.println(entry.getKey() + " " + entry.getValue());
  31.  
    }
  32.  
    }
  33.  
    }
  34.  
     
  35.  
    }
posted @ 2018-06-29 14:16  割肉机  阅读(2662)  评论(0编辑  收藏  举报