乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      java hashMap 與Collections.unmodifiedMap

       X的世界 2012-10-29

      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)存,與原來的內(nèi)存變量不共享;
      • Collections.unmodifedMap(map);方法返回與參數(shù)map同樣映射的視圖,且該視圖不可更改。,但該視圖會(huì)隨著map的更改而得到更新。即map中的變化會(huì)及時(shí)反映到該視圖中。

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多