import java.util.IdentityHashMap;
/* 2017-02-18 15:03:46
* 实现机制与HashMap基本相似,但它在处理两个key相等时,比较独特
* 只有两个key严格 相等 == 才认为两个key 相等
* 普通的HashMap 只要equals 方法 比较返回ture 且他们的hashCode 值相等
* 允许使用null 做为key value 不保证顺序
*
*/
public class identityHashMapj {
public static void main(String[] args) {
IdentityHashMap identityHashMap = new IdentityHashMap<>();
identityHashMap.put(new String("asd"), new String("123"));
identityHashMap.put( new String("a"), new String("1"));
identityHashMap.put( new String("a"), new String("2"));
identityHashMap.put( new String("s"), new String("2"));
/*
* 只有==返回true时 才会认为他们是同一个key
*/
System.out.println(identityHashMap);
}
}
IdentityHashMap
最新推荐文章于 2022-12-13 10:36:15 发布