免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
java hashMap 與Collections.unmodifiedMap

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;


public class HashMapTest {
    public static void main(String[] args){
     Map  map=new HashMap<String ,Integer>();
     map.put("1", 1);
     map.put("2", 3);
   
     System.out.println(map.get("2"));
     Map map3=new HashMap<String,Integer>(map);
     map3.put("1", 4);
     
     System.out.println(map.get("1"));
     Map map2=Collections.unmodifiableMap(new HashMap<String,Integer>(map));
     
     System.out.println(map2.get("2"));
     map.put("2", 5);
     System.out.println(map2.get("2"));
     System.out.println(map.get("2"));
         
     
     System.out.println(map2.size());
    }
}
輸出結(jié)果:
3
1
3
3
5
2
如果把上述程序中紅色部分改為Map map2=Collections.unmodifiableMap(map);
則輸出結(jié)果為:
3
1
3
5
5
2
從上可以得出以下結(jié)論:
  • HashMap的復(fù)制構(gòu)造方法new HashMap<String,Integer>(map);中會(huì)為新對(duì)象構(gòu)造新內(nèi)存,與原來(lái)的內(nèi)存變量不共享;
  • Collections.unmodifedMap(map);方法返回與參數(shù)map同樣映射的視圖,且該視圖不可更改。,但該視圖會(huì)隨著map的更改而得到更新。即map中的變化會(huì)及時(shí)反映到該視圖中。
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
java集合視圖
Java中的map集合順序如何與添加順序一樣
Google Guava Collections 使用介紹
Slobodan Celenkovic‘s Weblog : Weblog
JAVA基礎(chǔ) 之 Collections
Java集合框架
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服