来看一段代码,猜一下运行结果!
//给 list 放入 2个map对象
Listlist = new ArrayList();
Map map1 = new HashMap();
map1.put("name","张三");
map1.put("count",2);
list.add(map1);
Map map2 = new HashMap();
map2.put("name","李四");
map2.put("count",3);
list.add(map2);
//遍历 list , 并按照 map 的 count 数,生成 多个map,并为map 添加上 index
int index = 1;
Listresult = new ArrayList();
for(Map m : list){
int count = (Integer) m.get("count");
//循环count
for(int i=0;i
输出结果:
浅复制:
//给 list 放入 2个map对象
Listlist = new ArrayList();
Map map1 = new HashMap();
map1.put("name","张三");
map1.put("count",2);
list.add(map1);
Map map2 = new HashMap();
map2.put("name","李四");
map2.put("count",3);
list.add(map2);
//遍历 list , 并按照 map 的 count 数,生成 多个map,并为map 添加上 index
int index = 1;
Listresult = new ArrayList();
for(Map m : list){
int count = (Integer) m.get("count");
//循环count
for(int i=0;i
打印结果:
深度复制:
//给 list 放入 2个map对象
Listlist = new ArrayList();
Map map1 = new HashMap();
map1.put("name","张三");
map1.put("count",2);
list.add(map1);
Map map2 = new HashMap();
map2.put("name","李四");
map2.put("count",3);
list.add(map2);
//遍历 list , 并按照 map 的 count 数,生成 多个map,并为map 添加上 index
int index = 1;
Listresult = new ArrayList();
for(Map m : list){
int count = (Integer) m.get("count");
//循环count
for(int i=0;i
运行结果:
感谢您的支持,如对您有所帮助,请您打赏,谢谢啦~