Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/java/util/IdentityHashMap#pubctors) \| [Methods](https://developer.android.com/reference/java/util/IdentityHashMap#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/util/IdentityHashMap#inhmethods)

# IdentityHashMap


`
public


class
IdentityHashMap
`


`


`

`

extends https://developer.android.com/reference/java/util/AbstractMap<K, V>


`

`


implements

https://developer.android.com/reference/java/lang/Cloneable,

https://developer.android.com/reference/java/util/Map<K, V>,

https://developer.android.com/reference/java/io/Serializable


`

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) |||
| ↳ | [java.util.AbstractMap](https://developer.android.com/reference/java/util/AbstractMap)\<K, V\> ||
|   | ↳ | java.util.IdentityHashMap\<K, V\> |

<br />

*** ** * ** ***

This class implements the `Map` interface with a hash table, using
reference-equality in place of object-equality when comparing keys (and
values). In other words, in an `IdentityHashMap`, two keys
`k1` and `k2` are considered equal if and only if
`(k1==k2)`. (In normal `Map` implementations (like
`HashMap`) two keys `k1` and `k2` are considered equal
if and only if `(k1==null ? k2==null : k1.equals(k2))`.)

**This class is *not* a general-purpose `Map`
implementation! While this class implements the `Map` interface, it
intentionally violates `Map's` general contract, which mandates the
use of the `equals` method when comparing objects. This class is
designed for use only in the rare cases wherein reference-equality
semantics are required.**

The view collections of this map also have reference-equality semantics
for their elements. See the `https://developer.android.com/reference/java/util/IdentityHashMap#keySet()`, `https://developer.android.com/reference/java/util/IdentityHashMap#values()`,
and `https://developer.android.com/reference/java/util/IdentityHashMap#entrySet()` methods for further information.

A typical use of this class is *topology-preserving object graph transformations*, such as serialization or deep-copying. To perform such
a transformation, a program must maintain a "node table" that keeps track
of all the object references that have already been processed. The node
table must not equate distinct objects even if they happen to be equal.
Another typical use of this class is to maintain *proxy objects*. For
example, a debugging facility might wish to maintain a proxy object for
each object in the program being debugged.

This class provides all of the optional map operations, and permits
`null` values and the `null` key. This class makes no
guarantees as to the order of the map; in particular, it does not guarantee
that the order will remain constant over time.

This class provides constant-time performance for the basic
operations (`get` and `put`), assuming the system
identity hash function (`https://developer.android.com/reference/java/lang/System#identityHashCode(java.lang.Object)`)
disperses elements properly among the buckets.

This class has one tuning parameter (which affects performance but not
semantics): *expected maximum size*. This parameter is the maximum
number of key-value mappings that the map is expected to hold. Internally,
this parameter is used to determine the number of buckets initially
comprising the hash table. The precise relationship between the expected
maximum size and the number of buckets is unspecified.

If the size of the map (the number of key-value mappings) sufficiently
exceeds the expected maximum size, the number of buckets is increased.
Increasing the number of buckets ("rehashing") may be fairly expensive, so
it pays to create identity hash maps with a sufficiently large expected
maximum size. On the other hand, iteration over collection views requires
time proportional to the number of buckets in the hash table, so it
pays not to set the expected maximum size too high if you are especially
concerned with iteration performance or memory usage.

**Note that this implementation is not synchronized.**
If multiple threads access an identity hash map concurrently, and at
least one of the threads modifies the map structurally, it *must*
be synchronized externally. (A structural modification is any operation
that adds or deletes one or more mappings; merely changing the value
associated with a key that an instance already contains is not a
structural modification.) This is typically accomplished by
synchronizing on some object that naturally encapsulates the map.

If no such object exists, the map should be "wrapped" using the
`https://developer.android.com/reference/java/util/Collections#synchronizedMap(java.util.Map<K,V>)`
method. This is best done at creation time, to prevent accidental
unsynchronized access to the map:

```
  Map m = Collections.synchronizedMap(new IdentityHashMap(...));
```

The iterators returned by the `iterator` method of the
collections returned by all of this class's "collection view
methods" are *fail-fast*: if the map is structurally modified
at any time after the iterator is created, in any way except
through the iterator's own `remove` method, the iterator
will throw a `https://developer.android.com/reference/java/util/ConcurrentModificationException`. Thus, in the
face of concurrent modification, the iterator fails quickly and
cleanly, rather than risking arbitrary, non-deterministic behavior
at an undetermined time in the future.

Note that the fail-fast behavior of an iterator cannot be guaranteed
as it is, generally speaking, impossible to make any hard guarantees in the
presence of unsynchronized concurrent modification. Fail-fast iterators
throw `ConcurrentModificationException` on a best-effort basis.
Therefore, it would be wrong to write a program that depended on this
exception for its correctness: *fail-fast iterators should be used only to detect bugs.*

This class is a member of the
[Java Collections Framework](https://reference/java/util/package-summary.html#CollectionsFramework).
**See also:**

- `https://developer.android.com/reference/java/lang/System#identityHashCode(java.lang.Object)`
- `https://developer.android.com/reference/java/lang/Object#hashCode()`
- `https://developer.android.com/reference/java/util/Collection`
- `https://developer.android.com/reference/java/util/Map`
- `https://developer.android.com/reference/java/util/HashMap`
- `https://developer.android.com/reference/java/util/TreeMap`

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/java/util/IdentityHashMap#IdentityHashMap()() ` Constructs a new, empty identity hash map with a default expected maximum size (21). |
| ` https://developer.android.com/reference/java/util/IdentityHashMap#IdentityHashMap(int)(int expectedMaxSize) ` Constructs a new, empty map with the specified expected maximum size. |
| ` https://developer.android.com/reference/java/util/IdentityHashMap#IdentityHashMap(java.util.Map<?%20extends%20K,?%20extends%20V>)(https://developer.android.com/reference/java/util/Map<? extends K, ? extends V> m) ` Constructs a new identity hash map containing the key-value mappings in the specified map. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/java/util/IdentityHashMap#clear()() ` Removes all of the mappings from this map. |
| ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/util/IdentityHashMap#clone()() ` Returns a shallow copy of this identity hash map: the keys and values themselves are not cloned. |
| ` boolean` | ` https://developer.android.com/reference/java/util/IdentityHashMap#containsKey(java.lang.Object)(https://developer.android.com/reference/java/lang/Object key) ` Tests whether the specified object reference is a key in this identity hash map. |
| ` boolean` | ` https://developer.android.com/reference/java/util/IdentityHashMap#containsValue(java.lang.Object)(https://developer.android.com/reference/java/lang/Object value) ` Tests whether the specified object reference is a value in this identity hash map. |
| ` https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/util/Map.Entry<K, V>>` | ` https://developer.android.com/reference/java/util/IdentityHashMap#entrySet()() ` Returns a `https://developer.android.com/reference/java/util/Set` view of the mappings contained in this map. |
| ` boolean` | ` https://developer.android.com/reference/java/util/IdentityHashMap#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object o) ` Compares the specified object with this map for equality. |
| ` void` | ` https://developer.android.com/reference/java/util/IdentityHashMap#forEach(java.util.function.BiConsumer<?%20super%20K,?%20super%20V>)(https://developer.android.com/reference/java/util/function/BiConsumer<? super K, ? super V> action) ` Performs the given action for each entry in this map until all entries have been processed or the action throws an exception. |
| ` V` | ` https://developer.android.com/reference/java/util/IdentityHashMap#get(java.lang.Object)(https://developer.android.com/reference/java/lang/Object key) ` Returns the value to which the specified key is mapped, or `null` if this map contains no mapping for the key. |
| ` int` | ` https://developer.android.com/reference/java/util/IdentityHashMap#hashCode()() ` Returns the hash code value for this map. |
| ` boolean` | ` https://developer.android.com/reference/java/util/IdentityHashMap#isEmpty()() ` Returns `true` if this identity hash map contains no key-value mappings. |
| ` https://developer.android.com/reference/java/util/Set<K>` | ` https://developer.android.com/reference/java/util/IdentityHashMap#keySet()() ` Returns an identity-based set view of the keys contained in this map. |
| ` V` | ` https://developer.android.com/reference/java/util/IdentityHashMap#put(K,%20V)(K key, V value) ` Associates the specified value with the specified key in this identity hash map. |
| ` void` | ` https://developer.android.com/reference/java/util/IdentityHashMap#putAll(java.util.Map<?%20extends%20K,?%20extends%20V>)(https://developer.android.com/reference/java/util/Map<? extends K, ? extends V> m) ` Copies all of the mappings from the specified map to this map. |
| ` boolean` | ` https://developer.android.com/reference/java/util/IdentityHashMap#remove(java.lang.Object,%20java.lang.Object)(https://developer.android.com/reference/java/lang/Object key, https://developer.android.com/reference/java/lang/Object value) ` Removes the entry for the specified key only if it is currently mapped to the specified value (optional operation). More formally, if this map contains a mapping from a key `k` to a value `v` such that `(key == k)` and `(value == v)`, then this method removes the mapping for this key and returns `true`; otherwise it returns `false`. |
| ` V` | ` https://developer.android.com/reference/java/util/IdentityHashMap#remove(java.lang.Object)(https://developer.android.com/reference/java/lang/Object key) ` Removes the mapping for this key from this map if present. |
| ` boolean` | ` https://developer.android.com/reference/java/util/IdentityHashMap#replace(K,%20V,%20V)(K key, V oldValue, V newValue) ` Replaces the entry for the specified key only if currently mapped to the specified value (optional operation). More formally, if this map contains a mapping from a key `k` to a value `v` such that `(key == k)` and `(oldValue == v)`, then this method associates `k` with `newValue` and returns `true`; otherwise it returns `false`. |
| ` void` | ` https://developer.android.com/reference/java/util/IdentityHashMap#replaceAll(java.util.function.BiFunction<?%20super%20K,?%20super%20V,?%20extends%20V>)(https://developer.android.com/reference/java/util/function/BiFunction<? super K, ? super V, ? extends V> function) ` Replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception (optional operation). |
| ` int` | ` https://developer.android.com/reference/java/util/IdentityHashMap#size()() ` Returns the number of key-value mappings in this identity hash map. |
| ` https://developer.android.com/reference/java/util/Collection<V>` | ` https://developer.android.com/reference/java/util/IdentityHashMap#values()() ` Returns a `https://developer.android.com/reference/java/util/Collection` view of the values contained in this map. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/util/AbstractMap ` |---|---| | ` void` | ` https://developer.android.com/reference/java/util/AbstractMap#clear()() ` Removes all of the mappings from this map (optional operation). | | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/util/AbstractMap#clone()() ` Returns a shallow copy of this `AbstractMap` instance: the keys and values themselves are not cloned. | | ` boolean` | ` https://developer.android.com/reference/java/util/AbstractMap#containsKey(java.lang.Object)(https://developer.android.com/reference/java/lang/Object key) ` Returns `true` if this map contains a mapping for the specified key. | | ` boolean` | ` https://developer.android.com/reference/java/util/AbstractMap#containsValue(java.lang.Object)(https://developer.android.com/reference/java/lang/Object value) ` Returns `true` if this map maps one or more keys to the specified value. | | ` abstract https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/util/Map.Entry<K, V>>` | ` https://developer.android.com/reference/java/util/AbstractMap#entrySet()() ` Returns a `https://developer.android.com/reference/java/util/Set` view of the mappings contained in this map. | | ` boolean` | ` https://developer.android.com/reference/java/util/AbstractMap#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object o) ` Compares the specified object with this map for equality. | | ` V` | ` https://developer.android.com/reference/java/util/AbstractMap#get(java.lang.Object)(https://developer.android.com/reference/java/lang/Object key) ` Returns the value to which the specified key is mapped, or `null` if this map contains no mapping for the key. | | ` int` | ` https://developer.android.com/reference/java/util/AbstractMap#hashCode()() ` Returns the hash code value for this map. | | ` boolean` | ` https://developer.android.com/reference/java/util/AbstractMap#isEmpty()() ` Returns `true` if this map contains no key-value mappings. | | ` https://developer.android.com/reference/java/util/Set<K>` | ` https://developer.android.com/reference/java/util/AbstractMap#keySet()() ` Returns a `https://developer.android.com/reference/java/util/Set` view of the keys contained in this map. | | ` V` | ` https://developer.android.com/reference/java/util/AbstractMap#put(K,%20V)(K key, V value) ` Associates the specified value with the specified key in this map (optional operation). | | ` void` | ` https://developer.android.com/reference/java/util/AbstractMap#putAll(java.util.Map<?%20extends%20K,?%20extends%20V>)(https://developer.android.com/reference/java/util/Map<? extends K, ? extends V> m) ` Copies all of the mappings from the specified map to this map (optional operation). | | ` V` | ` https://developer.android.com/reference/java/util/AbstractMap#remove(java.lang.Object)(https://developer.android.com/reference/java/lang/Object key) ` Removes the mapping for a key from this map if it is present (optional operation). | | ` int` | ` https://developer.android.com/reference/java/util/AbstractMap#size()() ` Returns the number of key-value mappings in this map. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/util/AbstractMap#toString()() ` Returns a string representation of this map. | | ` https://developer.android.com/reference/java/util/Collection<V>` | ` https://developer.android.com/reference/java/util/AbstractMap#values()() ` Returns a `https://developer.android.com/reference/java/util/Collection` view of the values contained in this map. | ||
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||
| From interface ` https://developer.android.com/reference/java/util/Map ` |---|---| | ` abstract void` | ` https://developer.android.com/reference/java/util/Map#clear()() ` Removes all of the mappings from this map (optional operation). | | ` default V` | ` https://developer.android.com/reference/java/util/Map#compute(K,%20java.util.function.BiFunction<?%20super%20K,?%20super%20V,?%20extends%20V>)(K key, https://developer.android.com/reference/java/util/function/BiFunction<? super K, ? super V, ? extends V> remappingFunction) ` Attempts to compute a mapping for the specified key and its current mapped value, or `null` if there is no current mapping (optional operation). | | ` default V` | ` https://developer.android.com/reference/java/util/Map#computeIfAbsent(K,%20java.util.function.Function<?%20super%20K,?%20extends%20V>)(K key, https://developer.android.com/reference/java/util/function/Function<? super K, ? extends V> mappingFunction) ` If the specified key is not already associated with a value (or is mapped to `null`), attempts to compute its value using the given mapping function and enters it into this map unless `null` (optional operation). | | ` default V` | ` https://developer.android.com/reference/java/util/Map#computeIfPresent(K,%20java.util.function.BiFunction<?%20super%20K,?%20super%20V,?%20extends%20V>)(K key, https://developer.android.com/reference/java/util/function/BiFunction<? super K, ? super V, ? extends V> remappingFunction) ` If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value (optional operation). | | ` abstract boolean` | ` https://developer.android.com/reference/java/util/Map#containsKey(java.lang.Object)(https://developer.android.com/reference/java/lang/Object key) ` Returns `true` if this map contains a mapping for the specified key. | | ` abstract boolean` | ` https://developer.android.com/reference/java/util/Map#containsValue(java.lang.Object)(https://developer.android.com/reference/java/lang/Object value) ` Returns `true` if this map maps one or more keys to the specified value. | | ` static <K, V> https://developer.android.com/reference/java/util/Map<K, V>` | ` https://developer.android.com/reference/java/util/Map#copyOf(java.util.Map<?%20extends%20K,?%20extends%20V>)(https://developer.android.com/reference/java/util/Map<? extends K, ? extends V> map) ` Returns an [unmodifiable Map](https://developer.android.com/reference/java/util/IdentityHashMap#unmodifiable) containing the entries of the given Map. | | ` static <K, V> https://developer.android.com/reference/java/util/Map.Entry<K, V>` | ` https://developer.android.com/reference/java/util/Map#entry(K,%20V)(K k, V v) ` Returns an unmodifiable `https://developer.android.com/reference/java/util/Map.Entry` containing the given key and value. | | ` abstract https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/util/Map.Entry<K, V>>` | ` https://developer.android.com/reference/java/util/Map#entrySet()() ` Returns a `https://developer.android.com/reference/java/util/Set` view of the mappings contained in this map. | | ` abstract boolean` | ` https://developer.android.com/reference/java/util/Map#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object o) ` Compares the specified object with this map for equality. | | ` default void` | ` https://developer.android.com/reference/java/util/Map#forEach(java.util.function.BiConsumer<?%20super%20K,?%20super%20V>)(https://developer.android.com/reference/java/util/function/BiConsumer<? super K, ? super V> action) ` Performs the given action for each entry in this map until all entries have been processed or the action throws an exception. | | ` abstract V` | ` https://developer.android.com/reference/java/util/Map#get(java.lang.Object)(https://developer.android.com/reference/java/lang/Object key) ` Returns the value to which the specified key is mapped, or `null` if this map contains no mapping for the key. | | ` default V` | ` https://developer.android.com/reference/java/util/Map#getOrDefault(java.lang.Object,%20V)(https://developer.android.com/reference/java/lang/Object key, V defaultValue) ` Returns the value to which the specified key is mapped, or `defaultValue` if this map contains no mapping for the key. | | ` abstract int` | ` https://developer.android.com/reference/java/util/Map#hashCode()() ` Returns the hash code value for this map. | | ` abstract boolean` | ` https://developer.android.com/reference/java/util/Map#isEmpty()() ` Returns `true` if this map contains no key-value mappings. | | ` abstract https://developer.android.com/reference/java/util/Set<K>` | ` https://developer.android.com/reference/java/util/Map#keySet()() ` Returns a `https://developer.android.com/reference/java/util/Set` view of the keys contained in this map. | | ` default V` | ` https://developer.android.com/reference/java/util/Map#merge(K,%20V,%20java.util.function.BiFunction<?%20super%20V,?%20super%20V,?%20extends%20V>)(K key, V value, https://developer.android.com/reference/java/util/function/BiFunction<? super V, ? super V, ? extends V> remappingFunction) ` If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value (optional operation). | | ` static <K, V> https://developer.android.com/reference/java/util/Map<K, V>` | ` https://developer.android.com/reference/java/util/Map#of(K,%20V,%20K,%20V,%20K,%20V,%20K,%20V,%20K,%20V)(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) ` Returns an unmodifiable map containing five mappings. | | ` static <K, V> https://developer.android.com/reference/java/util/Map<K, V>` | ` https://developer.android.com/reference/java/util/Map#of(K,%20V,%20K,%20V,%20K,%20V,%20K,%20V)(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) ` Returns an unmodifiable map containing four mappings. | | ` static <K, V> https://developer.android.com/reference/java/util/Map<K, V>` | ` https://developer.android.com/reference/java/util/Map#of(K,%20V)(K k1, V v1) ` Returns an unmodifiable map containing a single mapping. | | ` static <K, V> https://developer.android.com/reference/java/util/Map<K, V>` | ` https://developer.android.com/reference/java/util/Map#of(K,%20V,%20K,%20V,%20K,%20V,%20K,%20V,%20K,%20V,%20K,%20V,%20K,%20V,%20K,%20V)(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8) ` Returns an unmodifiable map containing eight mappings. | | ` static <K, V> https://developer.android.com/reference/java/util/Map<K, V>` | ` https://developer.android.com/reference/java/util/Map#of(K,%20V,%20K,%20V)(K k1, V v1, K k2, V v2) ` Returns an unmodifiable map containing two mappings. | | ` static <K, V> https://developer.android.com/reference/java/util/Map<K, V>` | ` https://developer.android.com/reference/java/util/Map#of(K,%20V,%20K,%20V,%20K,%20V)(K k1, V v1, K k2, V v2, K k3, V v3) ` Returns an unmodifiable map containing three mappings. | | ` static <K, V> https://developer.android.com/reference/java/util/Map<K, V>` | ` https://developer.android.com/reference/java/util/Map#of()() ` Returns an unmodifiable map containing zero mappings. | | ` static <K, V> https://developer.android.com/reference/java/util/Map<K, V>` | ` https://developer.android.com/reference/java/util/Map#of(K,%20V,%20K,%20V,%20K,%20V,%20K,%20V,%20K,%20V,%20K,%20V,%20K,%20V,%20K,%20V,%20K,%20V)(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9) ` Returns an unmodifiable map containing nine mappings. | | ` static <K, V> https://developer.android.com/reference/java/util/Map<K, V>` | ` https://developer.android.com/reference/java/util/Map#of(K,%20V,%20K,%20V,%20K,%20V,%20K,%20V,%20K,%20V,%20K,%20V)(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6) ` Returns an unmodifiable map containing six mappings. | | ` static <K, V> https://developer.android.com/reference/java/util/Map<K, V>` | ` https://developer.android.com/reference/java/util/Map#of(K,%20V,%20K,%20V,%20K,%20V,%20K,%20V,%20K,%20V,%20K,%20V,%20K,%20V)(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7) ` Returns an unmodifiable map containing seven mappings. | | ` static <K, V> https://developer.android.com/reference/java/util/Map<K, V>` | ` https://developer.android.com/reference/java/util/Map#of(K,%20V,%20K,%20V,%20K,%20V,%20K,%20V,%20K,%20V,%20K,%20V,%20K,%20V,%20K,%20V,%20K,%20V,%20K,%20V)(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9, K k10, V v10) ` Returns an unmodifiable map containing ten mappings. | | ` static <K, V> https://developer.android.com/reference/java/util/Map<K, V>` | ` https://developer.android.com/reference/java/util/Map#ofEntries(java.util.Map.Entry<?%20extends%20K,?%20extends%20V>[])(https://developer.android.com/reference/java/util/Map.Entry<? extends K, ? extends V> entries) ` Returns an unmodifiable map containing keys and values extracted from the given entries. | | ` abstract V` | ` https://developer.android.com/reference/java/util/Map#put(K,%20V)(K key, V value) ` Associates the specified value with the specified key in this map (optional operation). | | ` abstract void` | ` https://developer.android.com/reference/java/util/Map#putAll(java.util.Map<?%20extends%20K,?%20extends%20V>)(https://developer.android.com/reference/java/util/Map<? extends K, ? extends V> m) ` Copies all of the mappings from the specified map to this map (optional operation). | | ` default V` | ` https://developer.android.com/reference/java/util/Map#putIfAbsent(K,%20V)(K key, V value) ` If the specified key is not already associated with a value (or is mapped to `null`) associates it with the given value and returns `null`, else returns the current value (optional operation). | | ` default boolean` | ` https://developer.android.com/reference/java/util/Map#remove(java.lang.Object,%20java.lang.Object)(https://developer.android.com/reference/java/lang/Object key, https://developer.android.com/reference/java/lang/Object value) ` Removes the entry for the specified key only if it is currently mapped to the specified value (optional operation). | | ` abstract V` | ` https://developer.android.com/reference/java/util/Map#remove(java.lang.Object)(https://developer.android.com/reference/java/lang/Object key) ` Removes the mapping for a key from this map if it is present (optional operation). | | ` default boolean` | ` https://developer.android.com/reference/java/util/Map#replace(K,%20V,%20V)(K key, V oldValue, V newValue) ` Replaces the entry for the specified key only if currently mapped to the specified value (optional operation). | | ` default V` | ` https://developer.android.com/reference/java/util/Map#replace(K,%20V)(K key, V value) ` Replaces the entry for the specified key only if it is currently mapped to some value (optional operation). | | ` default void` | ` https://developer.android.com/reference/java/util/Map#replaceAll(java.util.function.BiFunction<?%20super%20K,?%20super%20V,?%20extends%20V>)(https://developer.android.com/reference/java/util/function/BiFunction<? super K, ? super V, ? extends V> function) ` Replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception (optional operation). | | ` abstract int` | ` https://developer.android.com/reference/java/util/Map#size()() ` Returns the number of key-value mappings in this map. | | ` abstract https://developer.android.com/reference/java/util/Collection<V>` | ` https://developer.android.com/reference/java/util/Map#values()() ` Returns a `https://developer.android.com/reference/java/util/Collection` view of the values contained in this map. | ||

## Public constructors

### IdentityHashMap

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public IdentityHashMap ()
```

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

<br />

### IdentityHashMap

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public IdentityHashMap (int expectedMaxSize)
```

Constructs a new, empty map with the specified expected maximum size.
Putting more than the expected number of key-value mappings into
the map may cause the internal data structure to grow, which may be
somewhat time-consuming.

<br />

| Parameters ||
|---|---|
| `expectedMaxSize` | `int`: the expected maximum size of the map <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `expectedMaxSize` is negative |

### IdentityHashMap

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public IdentityHashMap (Map<? extends K, ? extends V> m)
```

Constructs a new identity hash map containing the key-value mappings
in the specified map.

<br />

| Parameters ||
|---|---|
| `m` | `Map`: the map whose mappings are to be placed into this map <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` | if the specified map is null |

## Public methods

### clear

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void clear ()
```

Removes all of the mappings from this map.
The map will be empty after this call returns.

<br />

### clone

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Object clone ()
```

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

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/Object` | a shallow copy of this map <br /> |

### containsKey

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean containsKey (Object key)
```

Tests whether the specified object reference is a key in this identity
hash map. Returns `true` if and only if this map contains a mapping
with key `k` such that `(key == k)`.

<br />

| Parameters ||
|---|---|
| `key` | `Object`: possible key <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if the specified object reference is a key in this map <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/IdentityHashMap#containsValue(java.lang.Object)`

### containsValue

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean containsValue (Object value)
```

Tests whether the specified object reference is a value in this identity
hash map. Returns `true` if and only if this map contains a mapping
with value `v` such that `(value == v)`.

<br />

| Parameters ||
|---|---|
| `value` | `Object`: value whose presence in this map is to be tested <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if this map maps one or more keys to the specified object reference <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/IdentityHashMap#containsKey(java.lang.Object)`

### entrySet

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Set<Entry<K, V>> entrySet ()
```

Returns a `https://developer.android.com/reference/java/util/Set` view of the mappings contained in this map.
Each element in the returned set is a reference-equality-based
`Map.Entry`. The set is backed by the map, so changes
to the map are reflected in the set, and vice-versa. If the
map is modified while an iteration over the set is in progress,
the results of the iteration are undefined. The set supports
element removal, which removes the corresponding mapping from
the map, via the `Iterator.remove`, `Set.remove`,
`removeAll`, `retainAll` and `clear`
methods. It does not support the `add` or
`addAll` methods.

Like the backing map, the `Map.Entry` objects in the set
returned by this method define key and value equality as
reference-equality rather than object-equality. This affects the
behavior of the `equals` and `hashCode` methods of these
`Map.Entry` objects. A reference-equality based `Map.Entry
e` is equal to an object `o` if and only if `o` is a
`Map.Entry` and `e.getKey()==o.getKey() &&
e.getValue()==o.getValue()`. To accommodate these equals
semantics, the `hashCode` method returns
`System.identityHashCode(e.getKey()) ^
System.identityHashCode(e.getValue())`. (While the keys and values
are compared using reference equality, the `Map.Entry`
objects themselves are not.)

**Owing to the reference-equality-based semantics of the
`Map.Entry` instances in the set returned by this method,
it is possible that the symmetry and transitivity requirements of
the `https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)` contract may be violated if any of
the entries in the set is compared to a normal map entry, or if
the set returned by this method is compared to a set of normal map
entries (such as would be returned by a call to this method on a normal
map). However, the `Object.equals` contract is guaranteed to
hold among identity-based map entries, and among sets of such entries.**

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/util/Map.Entry<K, V>>` | a set view of the identity-mappings contained in this map <br /> |

### equals

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean equals (Object o)
```

Compares the specified object with this map for equality. Returns
`true` if the given object is also a map and the two maps
represent identical object-reference mappings. More formally, this
map is equal to another map `m` if and only if
`this.entrySet().equals(m.entrySet())`. See the
`https://developer.android.com/reference/java/util/IdentityHashMap#entrySet()` method for the specification of equality
of this map's entries.

**Owing to the reference-equality-based semantics of this map it is
possible that the symmetry and transitivity requirements of the
`Object.equals` contract may be violated if this map is compared
to a normal map. However, the `Object.equals` contract is
guaranteed to hold among `IdentityHashMap` instances.**

<br />

| Parameters ||
|---|---|
| `o` | `Object`: object to be compared for equality with this map <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if the specified object is equal to this map <br /> |

**See also:**

- `https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)`

### forEach

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void forEach (BiConsumer<? super K, ? super V> action)
```

Performs the given action for each entry in this map until all entries
have been processed or the action throws an exception. Unless
otherwise specified by the implementing class, actions are performed in
the order of entry set iteration (if an iteration order is specified.)
Exceptions thrown by the action are relayed to the caller.

<br />

| Parameters ||
|---|---|
| `action` | `BiConsumer`: The action to be performed for each entry <br /> |

### get

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public V get (Object key)
```

Returns the value to which the specified key is mapped,
or `null` if this map contains no mapping for the key.

More formally, if this map contains a mapping from a key
`k` to a value `v` such that `(key == k)`,
then this method returns `v`; otherwise it returns
`null`. (There can be at most one such mapping.)

A return value of `null` does not *necessarily*
indicate that the map contains no mapping for the key; it's also
possible that the map explicitly maps the key to `null`.
The `https://developer.android.com/reference/java/util/IdentityHashMap#containsKey(java.lang.Object)` operation may be used to
distinguish these two cases.

<br />

| Parameters ||
|---|---|
| `key` | `Object`: the key whose associated value is to be returned <br /> |

| Returns ||
|---|---|
| `V` | the value to which the specified key is mapped, or `null` if this map contains no mapping for the key <br /> |

**See also:**

- `https://developer.android.com/reference/java/util/IdentityHashMap#put(K,%20V)`

### hashCode

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int hashCode ()
```

Returns the hash code value for this map. The hash code of a map is
defined to be the sum of the hash codes of each entry of this map.
See the `https://developer.android.com/reference/java/util/IdentityHashMap#entrySet()` method for a specification of the
hash code of this map's entries.

This specification ensures that `m1.equals(m2)`
implies that `m1.hashCode()==m2.hashCode()` for any two
`IdentityHashMap` instances `m1` and `m2`, as
required by the general contract of `https://developer.android.com/reference/java/lang/Object#hashCode()`.

**Owing to the reference-equality-based semantics of the
`Map.Entry` instances in the set returned by this map's
`entrySet` method, it is possible that the contractual
requirement of `Object.hashCode` mentioned in the previous
paragraph will be violated if one of the two objects being compared is
an `IdentityHashMap` instance and the other is a normal map.**

<br />

| Returns ||
|---|---|
| `int` | the hash code value for this map <br /> |

**See also:**

- `https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)`
- `https://developer.android.com/reference/java/util/IdentityHashMap#equals(java.lang.Object)`

### isEmpty

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isEmpty ()
```

Returns `true` if this identity hash map contains no key-value
mappings.

<br />

| Returns ||
|---|---|
| `boolean` | `true` if this identity hash map contains no key-value mappings <br /> |

### keySet

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Set<K> keySet ()
```

Returns an identity-based set view of the keys contained in this map.
The set is backed by the map, so changes to the map are reflected in
the set, and vice-versa. If the map is modified while an iteration
over the set is in progress, the results of the iteration are
undefined. The set supports element removal, which removes the
corresponding mapping from the map, via the `Iterator.remove`,
`Set.remove`, `removeAll`, `retainAll`, and
`clear` methods. It does not support the `add` or
`addAll` methods.

**While the object returned by this method implements the
`Set` interface, it does *not* obey `Set's` general
contract. Like its backing map, the set returned by this method
defines element equality as reference-equality rather than
object-equality. This affects the behavior of its `contains`,
`remove`, `containsAll`, `equals`, and
`hashCode` methods.**

**The `equals` method of the returned set returns `true`
only if the specified object is a set containing exactly the same
object references as the returned set. The symmetry and transitivity
requirements of the `Object.equals` contract may be violated if
the set returned by this method is compared to a normal set. However,
the `Object.equals` contract is guaranteed to hold among sets
returned by this method.**

The `hashCode` method of the returned set returns the sum of
the *identity hashcodes* of the elements in the set, rather than
the sum of their hashcodes. This is mandated by the change in the
semantics of the `equals` method, in order to enforce the
general contract of the `Object.hashCode` method among sets
returned by this method.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/Set<K>` | an identity-based set view of the keys contained in this map <br /> |

**See also:**

- `https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)`
- `https://developer.android.com/reference/java/lang/System#identityHashCode(java.lang.Object)`

### put

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public V put (K key, 
                V value)
```

Associates the specified value with the specified key in this identity
hash map. If this map already `https://developer.android.com/reference/java/util/IdentityHashMap#containsKey(java.lang.Object)`
a mapping for the key, the old value is replaced, otherwise, a new mapping
is inserted into this map.

<br />

| Parameters ||
|---|---|
| `key` | `K`: the key with which the specified value is to be associated <br /> |
| `value` | `V`: the value to be associated with the specified key <br /> |

| Returns ||
|---|---|
| `V` | the previous value associated with `key`, or `null` if there was no mapping for `key`. (A `null` return can also indicate that the map previously associated `null` with `key`.) <br /> |

**See also:**

- `https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)`
- `https://developer.android.com/reference/java/util/IdentityHashMap#get(java.lang.Object)`
- `https://developer.android.com/reference/java/util/IdentityHashMap#containsKey(java.lang.Object)`

### putAll

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void putAll (Map<? extends K, ? extends V> m)
```

Copies all of the mappings from the specified map to this map.
For each mapping in the specified map, if this map already
`https://developer.android.com/reference/java/util/IdentityHashMap#containsKey(java.lang.Object)` a mapping for the key,
its value is replaced with the value from the specified map;
otherwise, a new mapping is inserted into this map.

<br />

| Parameters ||
|---|---|
| `m` | `Map`: mappings to be stored in this map <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` | if the specified map is null |

### remove

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean remove (Object key, 
                Object value)
```

Removes the entry for the specified key only if it is currently
mapped to the specified value (optional operation).

More formally, if this map contains a mapping from a key
`k` to a value `v` such that `(key == k)`
and `(value == v)`, then this method removes the mapping
for this key and returns `true`; otherwise it returns
`false`.

<br />

| Parameters ||
|---|---|
| `key` | `Object`: key with which the specified value is associated <br /> |
| `value` | `Object`: value expected to be associated with the specified key <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if the value was removed <br /> |

### remove

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public V remove (Object key)
```

Removes the mapping for this key from this map if present.
The mapping is removed if and only if the mapping has a key
`k` such that (key == k).

<br />

| Parameters ||
|---|---|
| `key` | `Object`: key whose mapping is to be removed from the map <br /> |

| Returns ||
|---|---|
| `V` | the previous value associated with `key`, or `null` if there was no mapping for `key`. (A `null` return can also indicate that the map previously associated `null` with `key`.) <br /> |

### replace

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean replace (K key, 
                V oldValue, 
                V newValue)
```

Replaces the entry for the specified key only if currently
mapped to the specified value (optional operation).

More formally, if this map contains a mapping from a key
`k` to a value `v` such that `(key == k)`
and `(oldValue == v)`, then this method associates
`k` with `newValue` and returns `true`;
otherwise it returns `false`.

<br />

| Parameters ||
|---|---|
| `key` | `K`: key with which the specified value is associated <br /> |
| `oldValue` | `V`: value expected to be associated with the specified key <br /> |
| `newValue` | `V`: value to be associated with the specified key <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if the value was replaced <br /> |

### replaceAll

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void replaceAll (BiFunction<? super K, ? super V, ? extends V> function)
```

Replaces each entry's value with the result of invoking the given
function on that entry until all entries have been processed or the
function throws an exception (optional operation). Exceptions thrown
by the function are relayed to the caller.

<br />

| Parameters ||
|---|---|
| `function` | `BiFunction`: the function to apply to each entry <br /> |

### size

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int size ()
```

Returns the number of key-value mappings in this identity hash map.

<br />

| Returns ||
|---|---|
| `int` | the number of key-value mappings in this map <br /> |

### values

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Collection<V> values ()
```

Returns a `https://developer.android.com/reference/java/util/Collection` view of the values contained in this map.
The collection is backed by the map, so changes to the map are
reflected in the collection, and vice-versa. If the map is
modified while an iteration over the collection is in progress,
the results of the iteration are undefined. The collection
supports element removal, which removes the corresponding
mapping from the map, via the `Iterator.remove`,
`Collection.remove`, `removeAll`,
`retainAll` and `clear` methods. It does not
support the `add` or `addAll` methods.

**While the object returned by this method implements the
`Collection` interface, it does *not* obey
`Collection's` general contract. Like its backing map,
the collection returned by this method defines element equality as
reference-equality rather than object-equality. This affects the
behavior of its `contains`, `remove` and
`containsAll` methods.**

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/Collection<V>` | a collection view of the values contained in this map <br /> |