list添加map问题

结论:
    list添加添加的是map的地址
 
List<Map<String, Object>> list = new ArrayList<>();
           Map<String, Object> map = new HashMap<>();
           for (int a = 0; a < 2; a++) {
                map.put("a", a);
                map.put("b", a);
                list.add(map);
           }
           System.out.println(list);
结果:
[{b=1, a=1}, {b=1, a=1}]
 
<<<<<<<<<<<=======分割线=====>>>>>>>>>>>>>>>>>>>>
 
List<Map<String, Object>> list = new ArrayList<>();
           for (int a = 0; a < 2; a++) {
                Map<String, Object> map = new HashMap<>();
                map.put("a", a);
                map.put("b", a);
                list.add(map);
           }
           System.out.println(list);
结果:
[{b=0, a=0}, {b=1, a=1}]

 

posted @ 2018-06-14 10:55  jwcc  阅读(480)  评论(0编辑  收藏  举报