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.   public class ListMap {

  7.   static List<Map> lis = new ArrayList<Map>();
  8.   static Map<Integer, String> map = new HashMap<Integer, String>();
  9.   static Map<Integer, Integer> ma = new HashMap<Integer, Integer>();

  10.   public static void main(String[] args) {

  11.   map.put(1, "aaa");
  12.   map.put(2, "bbb");
  13.   map.put(3, "ccc");

  14.   ma.put(1, 1);
  15.   ma.put(2, 2);
  16.   ma.put(3, 3);

  17.   lis.add(map);
  18.   lis.add(ma);

  19.   for (Map m : lis) {
  20.   Iterator<Map.Entry<Object, Object>> it = m.entrySet().iterator();
  21.   while (it.hasNext()) {
  22.   Map.Entry<Object, Object> entry = it.next();
  23.   System.out.println(entry.getKey() + " " + entry.getValue());
  24.   }
  25.   }
  26.   }

  27.   }