zoukankan      html  css  js  c++  java
  • IdentityHashMap

    区别与其他的键不能重复的容器,IdentityHashMap允许key值重复,但是——key必须是两个不同的对象,即对于k1和k2,当k1==k2时,IdentityHashMap认为两个key相等,而HashMap只有在k1.equals(k2) == true 时才会认为两个key相等。

    看一段代码:

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Map<String,String> map =new IdentityHashMap<String,String>(100);//初始化容器的大小
    String a="aa";
    String b=new String("aa"); 
    System.out.println(a==b);
    map.put(a, "cc");
    map.put(b, "bb");
    map.put("2", "dd");
    System.out.println(map.size());//3



    Map<String,String> map1 =new IdentityHashMap<String,String>(100);
    map1.put("11", "cc");
    map1.put(new String("11"), "bb"); //map1.put(new String("11").intern(), "bb"); 
    map1.put("2", "dd");
    System.out.println(map1.size());//3


    Map<Integer,String> map2 =new IdentityHashMap<Integer,String>(100);
    map2.put(127, "cc");
    map2.put(127, "bb"); 
    map2.put(2, "dd");
    System.out.println(map2.size());//2

    //超出常量池范围~~
    Map<Integer,String> map3 =new IdentityHashMap<Integer,String>(100);
    map3.put(128, "cc");
    map3.put(128, "bb"); 
    map3.put(2, "dd");
    System.out.println(map3.size()); //3


    }

  • 相关阅读:
    package.json作用
    github 发布项目
    kubernetes --> ConfigMap
    kubernetes1.9 手动安装
    python3 BeautifulSoup模块
    python3 requests模块
    ununtu16.04+python3+selenium+firefox环境搭建
    QQ空间动态内容,好友信息,点赞爬虫脚本
    k8s使用ceph作为后端存储挂载
    ceph存储安装配置
  • 原文地址:https://www.cnblogs.com/drcoding/p/4241664.html
Copyright © 2011-2022 走看看