java map 的复制,Java Map的深度复制和浅复制
來看一段代碼,猜一下運行結果!
//給 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
運行結果:
感謝您的支持,如對您有所幫助,請您打賞,謝謝啦~
總結
以上是生活随笔為你收集整理的java map 的复制,Java Map的深度复制和浅复制的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: php json返回sql,php –
- 下一篇: 网页文件都是php怎么修改,请问你们怎么
