# ArrayMap

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  
Summary:[Ctors](https://developer.android.com/reference/android/support/v4/util/ArrayMap#pubctors)\|[Methods](https://developer.android.com/reference/android/support/v4/util/ArrayMap#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/v4/util/ArrayMap#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/v4/util/ArrayMap#)  

# ArrayMap

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public


class
ArrayMap
`  
`


``

extends `[SimpleArrayMap](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap)`<K, V>


``


implements

Map<K, V>


`

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

<br />

*** ** * ** ***

ArrayMap is a generic key-\>value mapping data structure that is designed to be more memory efficient than a traditional[HashMap](https://developer.android.com/reference/java/util/HashMap), this implementation is a version of the platform's`android.util.ArrayMap`that can be used on older versions of the platform. It keeps its mappings in an array data structure -- an integer array of hash codes for each item, and an Object array of the key/value pairs. This allows it to avoid having to create an extra object for every entry put in to the map, and it also tries to control the growth of the size of these arrays more aggressively (since growing them only requires copying the entries in the array, not rebuilding a hash map).

If you don't need the standard Java container APIs provided here (iterators etc), consider using[SimpleArrayMap](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap)instead.

Note that this implementation is not intended to be appropriate for data structures that may contain large numbers of items. It is generally slower than a traditional HashMap, since lookups require a binary search and adds and removes require inserting and deleting entries in the array. For containers holding up to hundreds of items, the performance difference is not significant, less than 50%.

Because this container is intended to better balance memory use, unlike most other standard Java containers it will shrink its array as items are removed from it. Currently you have no control over this shrinking -- if you set a capacity and then remove an item, it may reduce the capacity to better match the current size. In the future an explicit call to set the capacity should turn off this aggressive shrinking behavior.

<br />

## Summary

|                                                                                                                                                 ### Public constructors                                                                                                                                                 ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[ArrayMap](https://developer.android.com/reference/android/support/v4/util/ArrayMap#ArrayMap())`() `                                                                                                                                                                                                              |
| ` `[ArrayMap](https://developer.android.com/reference/android/support/v4/util/ArrayMap#ArrayMap(int))`(int capacity) ` Create a new ArrayMap with a given initial capacity.                                                                                                                                          |
| ` `[ArrayMap](https://developer.android.com/reference/android/support/v4/util/ArrayMap#ArrayMap(android.support.v4.util.SimpleArrayMap))`(`[SimpleArrayMap](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap)` map) ` Create a new ArrayMap with the mappings from the given ArrayMap. |

|                                                                                                                                                                               ### Public methods                                                                                                                                                                                ||
|---------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` boolean`          | ` `[containsAll](https://developer.android.com/reference/android/support/v4/util/ArrayMap#containsAll(java.util.Collection<?>))`(Collection<?> collection) ` Determine if the array map contains all of the keys in the given collection.                                                                                                                  |
| ` Set<Entry<K, V>>` | ` `[entrySet](https://developer.android.com/reference/android/support/v4/util/ArrayMap#entrySet())`() ` Return a[Set](https://developer.android.com/reference/java/util/Set)for iterating over and interacting with all mappings in the array map.                                                                                                         |
| ` Set<K>`           | ` `[keySet](https://developer.android.com/reference/android/support/v4/util/ArrayMap#keySet())`() ` Return a[Set](https://developer.android.com/reference/java/util/Set)for iterating over and interacting with all keys in the array map.                                                                                                                 |
| ` void`             | ` `[putAll](https://developer.android.com/reference/android/support/v4/util/ArrayMap#putAll(java.util.Map<? extends K, ? extends V>))`(Map<? extends K, ? extends V> map) ` Perform a[put(Object, Object)](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap#put(K, V))of all key/value pairs in<var translate="no">map</var> |
| ` boolean`          | ` `[removeAll](https://developer.android.com/reference/android/support/v4/util/ArrayMap#removeAll(java.util.Collection<?>))`(Collection<?> collection) ` Remove all keys in the array map that exist in the given collection.                                                                                                                              |
| ` boolean`          | ` `[retainAll](https://developer.android.com/reference/android/support/v4/util/ArrayMap#retainAll(java.util.Collection<?>))`(Collection<?> collection) ` Remove all keys in the array map that do**not**exist in the given collection.                                                                                                                     |
| ` Collection<V>`    | ` `[values](https://developer.android.com/reference/android/support/v4/util/ArrayMap#values())`() ` Return a[Collection](https://developer.android.com/reference/java/util/Collection)for iterating over and interacting with all values in the array map.                                                                                                 |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v4/util/ArrayMap#)From class` `[android.support.v4.util.SimpleArrayMap](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap)` ` |------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` void`    | ` `[clear](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap#clear())`() ` Make the array map empty.                                                                                                                                                                                                                                                                                                                                                            | | ` boolean` | ` `[containsKey](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap#containsKey(java.lang.Object))`(Object key) ` Check whether a key exists in the array.                                                                                                                                                                                                                                                                                                       | | ` boolean` | ` `[containsValue](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap#containsValue(java.lang.Object))`(Object value) ` Check whether a value exists in the array.                                                                                                                                                                                                                                                                                               | | ` void`    | ` `[ensureCapacity](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap#ensureCapacity(int))`(int minimumCapacity) ` Ensure the array map can hold at least<var translate="no">minimumCapacity</var>items.                                                                                                                                                                                                                                                        | | ` boolean` | ` `[equals](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap#equals(java.lang.Object))`(Object object) ` <br /> This implementation returns false if the object is not a Map or SimpleArrayMap, or if the maps have different sizes.                                                                                                                                                                                                                           | | ` V`       | ` `[get](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap#get(java.lang.Object))`(Object key) ` Retrieve a value from the array.                                                                                                                                                                                                                                                                                                                               | | ` int`     | ` `[hashCode](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap#hashCode())`() ` <br />                                                                                                                                                                                                                                                                                                                                                                         | | ` int`     | ` `[indexOfKey](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap#indexOfKey(java.lang.Object))`(Object key) ` Returns the index of a key in the set.                                                                                                                                                                                                                                                                                                           | | ` boolean` | ` `[isEmpty](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap#isEmpty())`() ` Return true if the array map contains no items.                                                                                                                                                                                                                                                                                                                                  | | ` K`       | ` `[keyAt](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap#keyAt(int))`(int index) ` Return the key at the given index in the array.                                                                                                                                                                                                                                                                                                                          | | ` V`       | ` `[put](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap#put(K, V))`(K key, V value) ` Add a new value to the array map.                                                                                                                                                                                                                                                                                                                                      | | ` void`    | ` `[putAll](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap#putAll(android.support.v4.util.SimpleArrayMap<? extends K, ? extends V>))`(`[SimpleArrayMap](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap)`<? extends K, ? extends V> array) ` Perform a[put(Object, Object)](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap#put(K, V))of all key/value pairs in<var translate="no">array</var> | | ` V`       | ` `[remove](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap#remove(java.lang.Object))`(Object key) ` Remove an existing key from the array map.                                                                                                                                                                                                                                                                                                               | | ` V`       | ` `[removeAt](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap#removeAt(int))`(int index) ` Remove the key/value mapping at the given index.                                                                                                                                                                                                                                                                                                                   | | ` V`       | ` `[setValueAt](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap#setValueAt(int, V))`(int index, V value) ` Set the value at a given index in the array.                                                                                                                                                                                                                                                                                                       | | ` int`     | ` `[size](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap#size())`() ` Return the number of items in this array map.                                                                                                                                                                                                                                                                                                                                          | | ` String`  | ` `[toString](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap#toString())`() ` <br /> This implementation composes a string by iterating over its mappings.                                                                                                                                                                                                                                                                                                   | | ` V`       | ` `[valueAt](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap#valueAt(int))`(int index) ` Return the value at the given index in the array.                                                                                                                                                                                                                                                                                                                    | ||
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v4/util/ArrayMap#)From class` java.lang.Object ` |-------------------|-------------------------------| | ` Object`         | ` clone() `                   | | ` boolean`        | ` equals(Object arg0) `       | | ` void`           | ` finalize() `                | | ` final Class<?>` | ` getClass() `                | | ` int`            | ` hashCode() `                | | ` final void`     | ` notify() `                  | | ` final void`     | ` notifyAll() `               | | ` String`         | ` toString() `                | | ` final void`     | ` wait(long arg0, int arg1) ` | | ` final void`     | ` wait(long arg0) `           | | ` final void`     | ` wait() `                    | ||
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v4/util/ArrayMap#)From interface` java.util.Map ` |------------------------------|----------------------------------------------------------------------------------| | ` abstract void`             | ` clear() `                                                                      | | ` default V`                 | ` compute(K arg0, BiFunction<? super K, ? super V, ? extends V> arg1) `          | | ` default V`                 | ` computeIfAbsent(K arg0, Function<? super K, ? extends V> arg1) `               | | ` default V`                 | ` computeIfPresent(K arg0, BiFunction<? super K, ? super V, ? extends V> arg1) ` | | ` abstract boolean`          | ` containsKey(Object arg0) `                                                     | | ` abstract boolean`          | ` containsValue(Object arg0) `                                                   | | ` abstract Set<Entry<K, V>>` | ` entrySet() `                                                                   | | ` abstract boolean`          | ` equals(Object arg0) `                                                          | | ` default void`              | ` forEach(BiConsumer<? super K, ? super V> arg0) `                               | | ` abstract V`                | ` get(Object arg0) `                                                             | | ` default V`                 | ` getOrDefault(Object arg0, V arg1) `                                            | | ` abstract int`              | ` hashCode() `                                                                   | | ` abstract boolean`          | ` isEmpty() `                                                                    | | ` abstract Set<K>`           | ` keySet() `                                                                     | | ` default V`                 | ` merge(K arg0, V arg1, BiFunction<? super V, ? super V, ? extends V> arg2) `    | | ` abstract V`                | ` put(K arg0, V arg1) `                                                          | | ` abstract void`             | ` putAll(Map<? extends K, ? extends V> arg0) `                                   | | ` default V`                 | ` putIfAbsent(K arg0, V arg1) `                                                  | | ` default boolean`           | ` remove(Object arg0, Object arg1) `                                             | | ` abstract V`                | ` remove(Object arg0) `                                                          | | ` default boolean`           | ` replace(K arg0, V arg1, V arg2) `                                              | | ` default V`                 | ` replace(K arg0, V arg1) `                                                      | | ` default void`              | ` replaceAll(BiFunction<? super K, ? super V, ? extends V> arg0) `               | | ` abstract int`              | ` size() `                                                                       | | ` abstract Collection<V>`    | ` values() `                                                                     | ||

## Public constructors

### ArrayMap

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
ArrayMap ()
```

<br />

<br />

### ArrayMap

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
ArrayMap (int capacity)
```

Create a new ArrayMap with a given initial capacity.

<br />

|        Parameters        ||
|------------|--------------|
| `capacity` | `int` <br /> |

### ArrayMap

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
ArrayMap (SimpleArrayMap map)
```

Create a new ArrayMap with the mappings from the given ArrayMap.

<br />

|           Parameters           ||
|-------|-------------------------|
| `map` | `SimpleArrayMap` <br /> |

## Public methods

### containsAll

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean containsAll (Collection<?> collection)
```

Determine if the array map contains all of the keys in the given collection.

<br />

|                                         Parameters                                          ||
|--------------|-------------------------------------------------------------------------------|
| `collection` | `Collection`: The collection whose contents are to be checked against. <br /> |

|                                                                   Returns                                                                   ||
|-----------|----------------------------------------------------------------------------------------------------------------------------------|
| `boolean` | Returns true if this array map contains a key for every entry in<var translate="no">collection</var>, else returns false. <br /> |

### entrySet

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

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

Return a[Set](https://developer.android.com/reference/java/util/Set)for iterating over and interacting with all mappings in the array map.

**Note:**this is a very inefficient way to access the array contents, it requires generating a number of temporary objects.

**Note:**
the semantics of this Set are subtly different than that of a[HashMap](https://developer.android.com/reference/java/util/HashMap): most important, the[Map.Entry](https://developer.android.com/reference/java/util/Map.Entry)object returned by its iterator is a single object that exists for the entire iterator, so you can**not** hold on to it after calling[Iterator.next](https://developer.android.com/reference/java/util/Iterator#next()).

<br />

<br />

<br />

|          Returns           ||
|--------------------|--------|
| `Set<Entry<K, V>>` | <br /> |

### keySet

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

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

Return a[Set](https://developer.android.com/reference/java/util/Set)for iterating over and interacting with all keys in the array map.

**Note:**this is a fairly inefficient way to access the array contents, it requires generating a number of temporary objects.

<br />

<br />

|     Returns      ||
|----------|--------|
| `Set<K>` | <br /> |

### putAll

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

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

Perform a[put(Object, Object)](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap#put(K, V))of all key/value pairs in<var translate="no">map</var>

<br />

|                            Parameters                            ||
|-------|-----------------------------------------------------------|
| `map` | `Map`: The map whose contents are to be retrieved. <br /> |

### removeAll

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean removeAll (Collection<?> collection)
```

Remove all keys in the array map that exist in the given collection.

<br />

|                                           Parameters                                            ||
|--------------|-----------------------------------------------------------------------------------|
| `collection` | `Collection`: The collection whose contents are to be used to remove keys. <br /> |

|                                         Returns                                         ||
|-----------|------------------------------------------------------------------------------|
| `boolean` | Returns true if any keys were removed from the array map, else false. <br /> |

### retainAll

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean retainAll (Collection<?> collection)
```

Remove all keys in the array map that do**not**exist in the given collection.

<br />

|                                                    Parameters                                                    ||
|--------------|----------------------------------------------------------------------------------------------------|
| `collection` | `Collection`: The collection whose contents are to be used to determine which keys to keep. <br /> |

|                                         Returns                                         ||
|-----------|------------------------------------------------------------------------------|
| `boolean` | Returns true if any keys were removed from the array map, else false. <br /> |

### values

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

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

Return a[Collection](https://developer.android.com/reference/java/util/Collection)for iterating over and interacting with all values in the array map.

**Note:**this is a fairly inefficient way to access the array contents, it requires generating a number of temporary objects.

<br />

<br />

|         Returns         ||
|-----------------|--------|
| `Collection<V>` | <br /> |

-

  ## Interfaces

  - [Pools.Pool](https://developer.android.com/reference/android/support/v4/util/Pools.Pool)
-

  ## Classes

  - [ArrayMap](https://developer.android.com/reference/android/support/v4/util/ArrayMap)
  - [ArraySet](https://developer.android.com/reference/android/support/v4/util/ArraySet)
  - [AtomicFile](https://developer.android.com/reference/android/support/v4/util/AtomicFile)
  - [CircularArray](https://developer.android.com/reference/android/support/v4/util/CircularArray)
  - [CircularIntArray](https://developer.android.com/reference/android/support/v4/util/CircularIntArray)
  - [LongSparseArray](https://developer.android.com/reference/android/support/v4/util/LongSparseArray)
  - [LruCache](https://developer.android.com/reference/android/support/v4/util/LruCache)
  - [ObjectsCompat](https://developer.android.com/reference/android/support/v4/util/ObjectsCompat)
  - [Pair](https://developer.android.com/reference/android/support/v4/util/Pair)
  - [PatternsCompat](https://developer.android.com/reference/android/support/v4/util/PatternsCompat)
  - [Pools](https://developer.android.com/reference/android/support/v4/util/Pools)
  - [Pools.SimplePool](https://developer.android.com/reference/android/support/v4/util/Pools.SimplePool)
  - [Pools.SynchronizedPool](https://developer.android.com/reference/android/support/v4/util/Pools.SynchronizedPool)
  - [SimpleArrayMap](https://developer.android.com/reference/android/support/v4/util/SimpleArrayMap)
  - [SparseArrayCompat](https://developer.android.com/reference/android/support/v4/util/SparseArrayCompat)