1
2
3
4
5
6
|
List<Map<String,String>> list =
new
ArrayList<Map<String,String>>();
Map<String,String> m =
new
HashMap<String,String>();
for
(
int
i =
0
;i<
2
;i++){
m.put(
"key1"
, String.valueOf(i));
list.add(m);
}
|
这样list存储的是[{key1=1}, {key1=1}]不是希望的结果[{key1=0}, {key1=1}],解决的办法就是在循环体内每次重新new一个map.