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)). However, traditional mapping operations like #get(Object) and #put(Object, Object) 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.
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 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.
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Class ArrayMap<K,V> (2.0.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.0.0 (latest)](/java/docs/reference/google-http-client/latest/com.google.api.client.util.ArrayMap)\n- [1.47.1](/java/docs/reference/google-http-client/1.47.1/com.google.api.client.util.ArrayMap)\n- [1.46.3](/java/docs/reference/google-http-client/1.46.3/com.google.api.client.util.ArrayMap)\n- [1.45.3](/java/docs/reference/google-http-client/1.45.3/com.google.api.client.util.ArrayMap)\n- [1.44.2](/java/docs/reference/google-http-client/1.44.2/com.google.api.client.util.ArrayMap)\n- [1.43.2](/java/docs/reference/google-http-client/1.43.2/com.google.api.client.util.ArrayMap)\n- [1.42.3](/java/docs/reference/google-http-client/1.42.3/com.google.api.client.util.ArrayMap)\n- [1.41.8](/java/docs/reference/google-http-client/1.41.8/com.google.api.client.util.ArrayMap) \n\n public class ArrayMap\u003cK,V\u003e extends AbstractMap\u003cK,V\u003e implements Cloneable\n\nMemory-efficient map of keys to values with list-style random-access semantics.\n\nSupports null keys and values. Conceptually, the keys and values are stored in a simpler array\nin order to minimize memory use and provide for fast access to a key/value at a certain index\n(for example [#getKey(int)](/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)](/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)](/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\nkey/value pairs in the worst case.\n\nImplementation is not thread-safe. For a thread-safe choice instead use an implementation of\nConcurrentMap. \n\nInheritance\n-----------\n\n[Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \\\u003e [AbstractMap](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html) \\\u003e ArrayMap\\\u003cK,V\\\u003e \n\nImplements\n----------\n\n[Cloneable](https://docs.oracle.com/javase/8/docs/api/java/lang/Cloneable.html) \n\nInherited Members\n-----------------\n\n[Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) \n[Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) \n[Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) \n[Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) \n[Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) \n[Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) \n[Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-) \n[AbstractMap.clear()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#clear--) \n[AbstractMap.clone()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#clone--) \n[AbstractMap.containsKey(Object)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#containsKey-java.lang.Object-) \n[AbstractMap.containsValue(Object)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#containsValue-java.lang.Object-) \n[AbstractMap.entrySet()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#entrySet--) \n[AbstractMap.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#equals-java.lang.Object-) \n[AbstractMap.get(Object)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#get-java.lang.Object-) \n[AbstractMap.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#hashCode--) \n[AbstractMap.isEmpty()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#isEmpty--) \n[AbstractMap.keySet()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#keySet--) \n[AbstractMap.put(K,V)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#put-K-V-) \n[AbstractMap.putAll(Map\\\u003c? extends K,? extends V\\\u003e)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#putAll-java.util.Map\u003c? extends K-? extends V\u003e-) \n[AbstractMap.remove(Object)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#remove-java.lang.Object-) \n[AbstractMap.size()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#size--) \n[AbstractMap.toString()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#toString--) \n[AbstractMap.values()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#values--)\n\nStatic Methods\n--------------\n\n### \\\u003cK,V\\\u003ecreate()\n\n public static ArrayMap\u003cK,V\u003e \u003cK,V\u003ecreate()\n\nReturns a new instance of an array map with initial capacity of zero. Equivalent to calling the\ndefault constructor, except without the need to specify the type parameters. For example:\n`ArrayMap\u003cString, String\u003e map = ArrayMap.create();`.\n\n### \\\u003cK,V\\\u003ecreate(int initialCapacity)\n\n public static ArrayMap\u003cK,V\u003e \u003cK,V\u003ecreate(int initialCapacity)\n\nReturns a new instance of an array map of the given initial capacity. For example: `\nArrayMap\u003cString, String\u003e map = ArrayMap.create(8);`.\n\n### \\\u003cK,V\\\u003eof(Object\\[\\] keyValuePairs)\n\n public static ArrayMap\u003cK,V\u003e \u003cK,V\u003eof(Object[] keyValuePairs)\n\nReturns a new instance of an array map of the given key value pairs in alternating order. For\nexample: `ArrayMap\u003cString, String\u003e map = ArrayMap.of(\"key1\", \"value1\", \"key2\", \"value2\",\n...);`.\n\nWARNING: there is no compile-time checking of the `keyValuePairs` parameter to ensure\nthat the keys or values have the correct type, so if the wrong type is passed in, any problems\nwill occur at runtime. Also, there is no checking that the keys are unique, which the caller\nmust ensure is true.\n\nConstructors\n------------\n\n### ArrayMap()\n\n public ArrayMap()\n\nMethods\n-------\n\n### add(K key, V value)\n\n public final void add(K key, V value)\n\nAdds the key/value mapping at the end of the list. Behaves identically to `set(size(),\nkey, value)`.\n\n### clear()\n\n public void clear()\n\n**Overrides** \n[AbstractMap.clear()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#clear--)\n\n### clone()\n\n public ArrayMap\u003cK,V\u003e clone()\n\n**Overrides** \n[AbstractMap.clone()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#clone--)\n\n### containsKey(Object key)\n\n public final boolean containsKey(Object key)\n\nReturns whether there is a mapping for the given key.\n\n**Overrides** \n[AbstractMap.containsKey(Object)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#containsKey-java.lang.Object-)\n\n### containsValue(Object value)\n\n public final boolean containsValue(Object value)\n\n**Overrides** \n[AbstractMap.containsValue(Object)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#containsValue-java.lang.Object-)\n\n### ensureCapacity(int minCapacity)\n\n public final void ensureCapacity(int minCapacity)\n\nEnsures that the capacity of the internal arrays is at least a given capacity.\n\n### entrySet()\n\n public final Set\u003cMap.Entry\u003cK,V\u003e\u003e entrySet()\n\n**Overrides** \n[AbstractMap.entrySet()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#entrySet--)\n\n### get(Object key)\n\n public final V get(Object key)\n\nReturns the value set for the given key or `null` if there is no such mapping or if the\nmapping value is `null`.\n\n**Overrides** \n[AbstractMap.get(Object)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#get-java.lang.Object-)\n\n### getIndexOfKey(K key)\n\n public final int getIndexOfKey(K key)\n\nReturns the index of the given key or `-1` if there is no such key.\n\n### getKey(int index)\n\n public final K getKey(int index)\n\nReturns the key at the given index or `null` if out of bounds.\n\n### getValue(int index)\n\n public final V getValue(int index)\n\nReturns the value at the given index or `null` if out of bounds.\n\n### put(K key, V value)\n\n public final V put(K key, V value)\n\nSets the value for the given key, overriding any existing value.\n\n**Overrides** \n[AbstractMap.put(K,V)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#put-K-V-)\n\n### remove(int index)\n\n public final V remove(int index)\n\nRemoves the key/value mapping at the given index, or ignored if the index is out of bounds.\n\n### remove(Object key)\n\n public final V remove(Object key)\n\nRemoves the key-value pair of the given key, or ignore if the key cannot be found.\n\n**Overrides** \n[AbstractMap.remove(Object)](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#remove-java.lang.Object-)\n\n### set(int index, K key, V value)\n\n public final V set(int index, K key, V value)\n\nSets the key/value mapping at the given index, overriding any existing key/value mapping.\n\nThere is no checking done to ensure that the key does not already exist. Therefore, this\nmethod is dangerous to call unless the caller can be certain the key does not already exist in\nthe map.\n\n### set(int index, V value)\n\n public final V set(int index, V value)\n\nSets the value at the given index, overriding any existing value mapping.\n\n### size()\n\n public final int size()\n\nReturns the number of key-value pairs set.\n\n**Overrides** \n[AbstractMap.size()](https://docs.oracle.com/javase/8/docs/api/java/util/AbstractMap.html#size--)\n\n### trim()\n\n public final void trim()\n\nTrims the internal array storage to minimize memory usage."]]