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

Xin_So

关注

阅读 84

2022-05-23

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

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)

0 0 举报