0
点赞
收藏
分享

微信扫一扫

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}


作者:​​三号小玩家​​




举报

相关推荐

0 条评论