📜  Java.util.IdentityHashMap类

📅  最后修改于: 2020-11-14 06:18:08             🧑  作者: Mango


介绍

java.util.IdentityHashMap类使用哈希表实现Map接口,在比较键(和值)时使用引用相等代替对象相等。以下是IdentityHashMap的重点-

  • 此类提供所有可选的映射操作,并允许空值和空键。

  • 此类无法保证地图的顺序。特别是,它不能保证顺序会随着时间的推移保持恒定。

  • 在IdentityHashMap中,当且仅当(k1 == k2)时,两个键k1和k2才被视为相等;而在Map实现中(如HashMap),当且仅当(k1 == null?k2 == null:k1.equals(k2))。

类声明

以下是java.util.IdentityHashMap类的声明-

public class IdentityHashMap
   extends AbstractMap
   implements Map, Serializable, Cloneable

类的构造函数

Sr.No. Constructor & Description
1

IdentityHashMap()

This constructs a new, empty identity hash map with a default expected maximum size (21).

2

IdentityHashMap(int expectedMaxSize)

This constructs a new, empty map with the specified expected maximum size.

3

IdentityHashMap(Map m)

This constructs a new identity hash map containing the keys-value mappings in the specified map.

类方法

Sr.No. Method & Description
1 void clear()

This method removes all of the mappings from this map.

2 Object clone()

This method returns a shallow copy of this identity hash map: the keys and values themselves are not cloned.

3 boolean containsKey(Object key)

This method tests whether the specified object reference is a key in this identity hash map.

4 boolean containsValue(Object value)

This method tests whether the specified object reference is a value in this identity hash map.

5 Set> entrySet()

This method returns a Set view of the mappings contained in this map.

6 boolean equals(Object o)

This method compares the specified object with this map for equality.

7 V get(Object key)

This method returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

8 int hashCode()

This method returns returns the hash code value for this map.

9 boolean isEmpty()

This method returns true if this identity hash map contains no key-value mappings.

10 SetkeySet()

This method returns an identity-based set view of the keys contained in this map.

11 V put(K key, V value)

This method associates the specified value with the specified key in this identity hash map.

12 void putAll(Map m)

This method copies all of the mappings from the specified map to this map.

13 V remove(Object key)

This method removes the mapping for this key from this map if present.

14 int size()

This method returns the number of key-value mappings in this identity hash map.

15 Collection values()

This method returns returns a Collection view of the values contained in this map.

方法继承

此类从以下类继承方法-

  • java.util.AbstractMap
  • java.util.Object