java8原生jdk中的集合IdentityHashMap的使用

引用数据类型如果地址不同可以保存,基本类型保存不了

IdentityHashMap<String ,Integer> identityHashMap = new IdentityHashMap<>();
identityHashMap.put(new String("A"), 1);
identityHashMap.put(new String("B"), 2);
identityHashMap.put(new String("A"), 3);
System.out.println(identityHashMap);//{A=3, B=2, A=1}

IdentityHashMap<Integer ,Integer> map2 = new IdentityHashMap<>();
map2.put(1, 1);
map2.put(1, 1);
map2.put(1, 1);
System.out.println(map2);//{1=1}

HashMap<String ,Integer> hashmap = new HashMap<>();
hashmap.put(new String("A"), 1);
hashmap.put(new String("B"), 2);
hashmap.put(new String("A"), 3);
System.out.println(hashmap);//{A=3, B=2}

posted @   三号小玩家  阅读(68)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
Title
三号小玩家的 Mail: 17612457115@163.com, 联系QQ: 1359720840 微信: QQ1359720840

喜欢请打赏

扫描二维码打赏

支付宝打赏

点击右上角即可分享
微信分享提示