# Class ArrayMap&lt;K,V&gt; (2.1.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [2.1.0 (latest)](https://docs-0cloud-0google-0com.linkedin.net.nz/java/docs/reference/google-http-client/latest/com.google.api.client.util.ArrayMap)
- [2.0.3](https://docs-0cloud-0google-0com.linkedin.net.nz/java/docs/reference/google-http-client/2.0.3/com.google.api.client.util.ArrayMap)
- [1.47.1](https://docs-0cloud-0google-0com.linkedin.net.nz/java/docs/reference/google-http-client/1.47.1/com.google.api.client.util.ArrayMap)
- [1.46.3](https://docs-0cloud-0google-0com.linkedin.net.nz/java/docs/reference/google-http-client/1.46.3/com.google.api.client.util.ArrayMap)
- [1.45.3](https://docs-0cloud-0google-0com.linkedin.net.nz/java/docs/reference/google-http-client/1.45.3/com.google.api.client.util.ArrayMap)
- [1.44.2](https://docs-0cloud-0google-0com.linkedin.net.nz/java/docs/reference/google-http-client/1.44.2/com.google.api.client.util.ArrayMap)
- [1.43.2](https://docs-0cloud-0google-0com.linkedin.net.nz/java/docs/reference/google-http-client/1.43.2/com.google.api.client.util.ArrayMap)
- [1.42.3](https://docs-0cloud-0google-0com.linkedin.net.nz/java/docs/reference/google-http-client/1.42.3/com.google.api.client.util.ArrayMap)
- [1.41.8](https://docs-0cloud-0google-0com.linkedin.net.nz/java/docs/reference/google-http-client/1.41.8/com.google.api.client.util.ArrayMap)

    public class ArrayMap<K,V> extends AbstractMap<K,V> implements Cloneable

Memory-efficient map of keys to values with list-style random-access semantics.

Supports null keys and values. Conceptually, the keys and values are stored in a simpler array
in order to minimize memory use and provide for fast access to a key/value at a certain index
(for example [#getKey(int)](https://docs-0cloud-0google-0com.linkedin.net.nz/java/docs/reference/google-http-client/latest/com.google.api.client.util.ArrayMap#com_google_api_client_util_ArrayMap_getKey_int_)). However, traditional mapping operations like [#get(Object)](https://docs-0cloud-0google-0com.linkedin.net.nz/java/docs/reference/google-http-client/latest/com.google.api.client.util.ArrayMap#com_google_api_client_util_ArrayMap_get_java_lang_Object_) and [#put(Object, Object)](https://docs-0cloud-0google-0com.linkedin.net.nz/java/docs/reference/google-http-client/latest/com.google.api.client.util.ArrayMap#com_google_api_client_util_ArrayMap_put_) are slower because they need to look up all
key/value pairs in the worst case.

Implementation is not thread-safe. For a thread-safe choice instead use an implementation of
ConcurrentMap.

## Inheritance

[Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> [AbstractMap](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html) \> ArrayMap\<K,V\>

## Implements

[Cloneable](https://docs.oracle.com/javase/8/docs/api/java/lang/Cloneable.html)

## Inherited Members

[Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-) [AbstractMap.clear()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#clear--) [AbstractMap.clone()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#clone--) [AbstractMap.containsKey(Object)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#containsKey-java.lang.Object-) [AbstractMap.containsValue(Object)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#containsValue-java.lang.Object-) [AbstractMap.entrySet()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#entrySet--) [AbstractMap.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#equals-java.lang.Object-) [AbstractMap.get(Object)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#get-java.lang.Object-) [AbstractMap.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#hashCode--) [AbstractMap.isEmpty()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#isEmpty--) [AbstractMap.keySet()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#keySet--) [AbstractMap.put(K,V)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#put-K-V-) [AbstractMap.putAll(Map\<? extends K,? extends V\>)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#putAll-java.util.Map<? extends K-? extends V>-) [AbstractMap.remove(Object)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#remove-java.lang.Object-) [AbstractMap.size()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#size--) [AbstractMap.toString()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#toString--) [AbstractMap.values()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#values--)

| ## Type Parameters ||
|---|---|
| **Name** | **Description** |
| `K` |   |
| `V` |   |

## Static Methods

### \<K,V\>create()

    public static ArrayMap<K,V> <K,V>create()

Returns a new instance of an array map with initial capacity of zero. Equivalent to calling the
default constructor, except without the need to specify the type parameters. For example:
`ArrayMap<String, String> map = ArrayMap.create();`.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs-0cloud-0google-0com.linkedin.net.nz/java/docs/reference/google-http-client/latest/com.google.api.client.util.ArrayMap<K,V>` |   |

### \<K,V\>create(int initialCapacity)

    public static ArrayMap<K,V> <K,V>create(int initialCapacity)

Returns a new instance of an array map of the given initial capacity. For example: `
ArrayMap<String, String> map = ArrayMap.create(8);`.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `initialCapacity` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs-0cloud-0google-0com.linkedin.net.nz/java/docs/reference/google-http-client/latest/com.google.api.client.util.ArrayMap<K,V>` |   |

### \<K,V\>of(Object\[\] keyValuePairs)

    public static ArrayMap<K,V> <K,V>of(Object[] keyValuePairs)

Returns a new instance of an array map of the given key value pairs in alternating order. For
example: `ArrayMap<String, String> map = ArrayMap.of("key1", "value1", "key2", "value2",
...);`.

WARNING: there is no compile-time checking of the `keyValuePairs` parameter to ensure
that the keys or values have the correct type, so if the wrong type is passed in, any problems
will occur at runtime. Also, there is no checking that the keys are unique, which the caller
must ensure is true.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `keyValuePairs` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html[]` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs-0cloud-0google-0com.linkedin.net.nz/java/docs/reference/google-http-client/latest/com.google.api.client.util.ArrayMap<K,V>` |   |

## Constructors

### ArrayMap()

    public ArrayMap()

## Methods

### add(K key, V value)

    public final void add(K key, V value)

Adds the key/value mapping at the end of the list. Behaves identically to `set(size(),
key, value)`.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `key` | `K` |
| `value` | `V` |

### clear()

    public void clear()

**Overrides** [AbstractMap.clear()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#clear--)

### clone()

    public ArrayMap<K,V> clone()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs-0cloud-0google-0com.linkedin.net.nz/java/docs/reference/google-http-client/latest/com.google.api.client.util.ArrayMap<K,V>` |   |

**Overrides** [AbstractMap.clone()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#clone--)

### containsKey(Object key)

    public final boolean containsKey(Object key)

Returns whether there is a mapping for the given key.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `key` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

**Overrides** [AbstractMap.containsKey(Object)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#containsKey-java.lang.Object-)

### containsValue(Object value)

    public final boolean containsValue(Object value)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

**Overrides** [AbstractMap.containsValue(Object)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#containsValue-java.lang.Object-)

### ensureCapacity(int minCapacity)

    public final void ensureCapacity(int minCapacity)

Ensures that the capacity of the internal arrays is at least a given capacity.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `minCapacity` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

### entrySet()

    public final Set<Map.Entry<K,V>> entrySet()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/Set.html<https://docs.oracle.com/javase/8/docs/api/java/util/Map/Entry.html<K,V>>` |   |

**Overrides** [AbstractMap.entrySet()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#entrySet--)

### get(Object key)

    public final V get(Object key)

Returns the value set for the given key or `null` if there is no such mapping or if the
mapping value is `null`.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `key` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `V` |   |

**Overrides** [AbstractMap.get(Object)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#get-java.lang.Object-)

### getIndexOfKey(K key)

    public final int getIndexOfKey(K key)

Returns the index of the given key or `-1` if there is no such key.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `key` | `K` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### getKey(int index)

    public final K getKey(int index)

Returns the key at the given index or `null` if out of bounds.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `index` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `K` |   |

### getValue(int index)

    public final V getValue(int index)

Returns the value at the given index or `null` if out of bounds.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `index` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `V` |   |

### put(K key, V value)

    public final V put(K key, V value)

Sets the value for the given key, overriding any existing value.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `key` | `K` |
| `value` | `V` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `V` | previous value or `null` for none |

**Overrides** [AbstractMap.put(K,V)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#put-K-V-)

### remove(int index)

    public final V remove(int index)

Removes the key/value mapping at the given index, or ignored if the index is out of bounds.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `index` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `V` | previous value or `null` for none |

### remove(Object key)

    public final V remove(Object key)

Removes the key-value pair of the given key, or ignore if the key cannot be found.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `key` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `V` | previous value or `null` for none |

**Overrides** [AbstractMap.remove(Object)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#remove-java.lang.Object-)

### set(int index, K key, V value)

    public final V set(int index, K key, V value)

Sets the key/value mapping at the given index, overriding any existing key/value mapping.

There is no checking done to ensure that the key does not already exist. Therefore, this
method is dangerous to call unless the caller can be certain the key does not already exist in
the map.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `index` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |
| `key` | `K` |
| `value` | `V` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `V` | previous value or `null` for none |

### set(int index, V value)

    public final V set(int index, V value)

Sets the value at the given index, overriding any existing value mapping.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `index` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |
| `value` | `V` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `V` | previous value or `null` for none |

### size()

    public final int size()

Returns the number of key-value pairs set.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

**Overrides** [AbstractMap.size()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#size--)

### trim()

    public final void trim()

Trims the internal array storage to minimize memory usage.