# ArraySet

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

# ArraySet

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/util/ArraySet "View this page in Kotlin")\|Java

`
public

final

class
ArraySet
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


implements

`[Collection](https://developer.android.com/reference/java/util/Collection)`<E>,

`[Set](https://developer.android.com/reference/java/util/Set)`<E>


`

|---|----------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.util.ArraySet\<E\> |

<br />

*** ** * ** ***

ArraySet is a generic set data structure that is designed to be more memory efficient than a traditional[HashSet](https://developer.android.com/reference/java/util/HashSet). The design is very similar to[ArrayMap](https://developer.android.com/reference/android/util/ArrayMap), with all of the caveats described there. This implementation is separate from ArrayMap, however, so the Object array contains only one item for each entry in the set (instead of a pair for a mapping).

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 HashSet, 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.

This structure is**NOT**thread-safe.

<br />

## Summary

|                                                                                                                                    ### Public constructors                                                                                                                                    ||
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[ArraySet](https://developer.android.com/reference/android/util/ArraySet#ArraySet())`() ` Create a new empty ArraySet.                                                                                                                                                                  |
| ` `[ArraySet](https://developer.android.com/reference/android/util/ArraySet#ArraySet(android.util.ArraySet<E>))`(`[ArraySet](https://developer.android.com/reference/android/util/ArraySet)`<E> set) ` Create a new ArraySet with the mappings from the given ArraySet.                    |
| ` `[ArraySet](https://developer.android.com/reference/android/util/ArraySet#ArraySet(E[]))`(E[] array) ` Create a new ArraySet with items from the given array                                                                                                                             |
| ` `[ArraySet](https://developer.android.com/reference/android/util/ArraySet#ArraySet(int))`(int capacity) ` Create a new ArraySet with a given initial capacity.                                                                                                                           |
| ` `[ArraySet](https://developer.android.com/reference/android/util/ArraySet#ArraySet(java.util.Collection<?%20extends%20E>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<? extends E> set) ` Create a new ArraySet with items from the given collection. |

|                                                                                                                                                                                                                                      ### Public methods                                                                                                                                                                                                                                       ||
|--------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` boolean`                                                                     | ` `[add](https://developer.android.com/reference/android/util/ArraySet#add(E))`(E value) ` Adds the specified object to this set.                                                                                                                                                                                                                                                                             |
| ` boolean`                                                                     | ` `[addAll](https://developer.android.com/reference/android/util/ArraySet#addAll(java.util.Collection<?%20extends%20E>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<? extends E> collection) ` Perform an[add(java.lang.Object)](https://developer.android.com/reference/android/util/ArraySet#add(E))of all values in<var translate="no">collection</var>                 |
| ` void`                                                                        | ` `[addAll](https://developer.android.com/reference/android/util/ArraySet#addAll(android.util.ArraySet<?%20extends%20E>))`(`[ArraySet](https://developer.android.com/reference/android/util/ArraySet)`<? extends E> array) ` Perform a[add(java.lang.Object)](https://developer.android.com/reference/android/util/ArraySet#add(E))of all values in<var translate="no">array</var>                            |
| ` void`                                                                        | ` `[clear](https://developer.android.com/reference/android/util/ArraySet#clear())`() ` Make the array map empty.                                                                                                                                                                                                                                                                                              |
| ` boolean`                                                                     | ` `[contains](https://developer.android.com/reference/android/util/ArraySet#contains(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` key) ` Check whether a value exists in the set.                                                                                                                                                                                 |
| ` boolean`                                                                     | ` `[containsAll](https://developer.android.com/reference/android/util/ArraySet#containsAll(java.util.Collection<?>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<?> collection) ` Determine if the array set contains all of the values in the given collection.                                                                                                            |
| ` void`                                                                        | ` `[ensureCapacity](https://developer.android.com/reference/android/util/ArraySet#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/util/ArraySet#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` object) ` Indicates whether some other object is "equal to" this one. This implementation returns false if the object is not a set, or if the sets have different sizes.                                                            |
| ` void`                                                                        | ` `[forEach](https://developer.android.com/reference/android/util/ArraySet#forEach(java.util.function.Consumer<?%20super%20E>))`(`[Consumer](https://developer.android.com/reference/java/util/function/Consumer)`<? super E> action) ` Performs the given action for all elements in the stored order.                                                                                                       |
| ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/android/util/ArraySet#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                                                                                                                                        |
| ` int`                                                                         | ` `[indexOf](https://developer.android.com/reference/android/util/ArraySet#indexOf(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` key) ` Returns the index of a value in the set.                                                                                                                                                                                   |
| ` boolean`                                                                     | ` `[isEmpty](https://developer.android.com/reference/android/util/ArraySet#isEmpty())`() ` Return true if the array map contains no items.                                                                                                                                                                                                                                                                    |
| ` `[Iterator](https://developer.android.com/reference/java/util/Iterator)`<E>` | ` `[iterator](https://developer.android.com/reference/android/util/ArraySet#iterator())`() ` Return an[Iterator](https://developer.android.com/reference/java/util/Iterator)over all values in the set.                                                                                                                                                                                                       |
| ` boolean`                                                                     | ` `[remove](https://developer.android.com/reference/android/util/ArraySet#remove(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` object) ` Removes the specified object from this set.                                                                                                                                                                               |
| ` boolean`                                                                     | ` `[removeAll](https://developer.android.com/reference/android/util/ArraySet#removeAll(java.util.Collection<?>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<?> collection) ` Remove all values in the array set that exist in the given collection.                                                                                                                        |
| ` boolean`                                                                     | ` `[removeAll](https://developer.android.com/reference/android/util/ArraySet#removeAll(android.util.ArraySet<?%20extends%20E>))`(`[ArraySet](https://developer.android.com/reference/android/util/ArraySet)`<? extends E> array) ` Perform a[remove(java.lang.Object)](https://developer.android.com/reference/android/util/ArraySet#remove(java.lang.Object))of all values in<var translate="no">array</var> |
| ` E`                                                                           | ` `[removeAt](https://developer.android.com/reference/android/util/ArraySet#removeAt(int))`(int index) ` Remove the key/value mapping at the given index.                                                                                                                                                                                                                                                     |
| ` boolean`                                                                     | ` `[removeIf](https://developer.android.com/reference/android/util/ArraySet#removeIf(java.util.function.Predicate<?%20super%20E>))`(`[Predicate](https://developer.android.com/reference/java/util/function/Predicate)`<? super E> filter) ` Removes all values that satisfy the predicate.                                                                                                                   |
| ` boolean`                                                                     | ` `[retainAll](https://developer.android.com/reference/android/util/ArraySet#retainAll(java.util.Collection<?>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<?> collection) ` Remove all values in the array set that do**not**exist in the given collection.                                                                                                               |
| ` int`                                                                         | ` `[size](https://developer.android.com/reference/android/util/ArraySet#size())`() ` Return the number of items in this array map.                                                                                                                                                                                                                                                                            |
| ` <T> T[]`                                                                     | ` `[toArray](https://developer.android.com/reference/android/util/ArraySet#toArray(T[]))`(T[] array) ` Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array.                                                                                                                                                             |
| ` `[Object[]](https://developer.android.com/reference/java/lang/Object)        | ` `[toArray](https://developer.android.com/reference/android/util/ArraySet#toArray())`() ` Returns an array containing all of the elements in this collection.                                                                                                                                                                                                                                                |
| ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/android/util/ArraySet#toString())`() ` Returns a string representation of the object. This implementation composes a string by iterating over its values.                                                                                                                                                                                               |
| ` E`                                                                           | ` `[valueAt](https://developer.android.com/reference/android/util/ArraySet#valueAt(int))`(int index) ` Return the value at the given index in the array.                                                                                                                                                                                                                                                      |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](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 `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](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`                                                                  | ` `[wait](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`                                                                  | ` `[wait](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` `[java.util.Collection](https://developer.android.com/reference/java/util/Collection)` ` |----------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract boolean`                                                                          | ` `[add](https://developer.android.com/reference/java/util/Collection#add(E))`(E e) ` Ensures that this collection contains the specified element (optional operation).                                                                                                                                                                                                      | | ` abstract boolean`                                                                          | ` `[addAll](https://developer.android.com/reference/java/util/Collection#addAll(java.util.Collection<?%20extends%20E>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<? extends E> c) ` Adds all of the elements in the specified collection to this collection (optional operation).                                                        | | ` abstract void`                                                                             | ` `[clear](https://developer.android.com/reference/java/util/Collection#clear())`() ` Removes all of the elements from this collection (optional operation).                                                                                                                                                                                                                 | | ` abstract boolean`                                                                          | ` `[contains](https://developer.android.com/reference/java/util/Collection#contains(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` o) ` Returns`true`if this collection contains the specified element.                                                                                                                            | | ` abstract boolean`                                                                          | ` `[containsAll](https://developer.android.com/reference/java/util/Collection#containsAll(java.util.Collection<?>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<?> c) ` Returns`true`if this collection contains all of the elements in the specified collection.                                                                          | | ` abstract boolean`                                                                          | ` `[equals](https://developer.android.com/reference/java/util/Collection#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` o) ` Compares the specified object with this collection for equality.                                                                                                                               | | ` abstract int`                                                                              | ` `[hashCode](https://developer.android.com/reference/java/util/Collection#hashCode())`() ` Returns the hash code value for this collection.                                                                                                                                                                                                                                 | | ` abstract boolean`                                                                          | ` `[isEmpty](https://developer.android.com/reference/java/util/Collection#isEmpty())`() ` Returns`true`if this collection contains no elements.                                                                                                                                                                                                                              | | ` abstract `[Iterator](https://developer.android.com/reference/java/util/Iterator)`<E>`      | ` `[iterator](https://developer.android.com/reference/java/util/Collection#iterator())`() ` Returns an iterator over the elements in this collection.                                                                                                                                                                                                                        | | ` default `[Stream](https://developer.android.com/reference/java/util/stream/Stream)`<E>`    | ` `[parallelStream](https://developer.android.com/reference/java/util/Collection#parallelStream())`() ` Returns a possibly parallel`Stream`with this collection as its source.                                                                                                                                                                                               | | ` abstract boolean`                                                                          | ` `[remove](https://developer.android.com/reference/java/util/Collection#remove(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` o) ` Removes a single instance of the specified element from this collection, if it is present (optional operation).                                                                                | | ` abstract boolean`                                                                          | ` `[removeAll](https://developer.android.com/reference/java/util/Collection#removeAll(java.util.Collection<?>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<?> c) ` Removes all of this collection's elements that are also contained in the specified collection (optional operation).                                                    | | ` default boolean`                                                                           | ` `[removeIf](https://developer.android.com/reference/java/util/Collection#removeIf(java.util.function.Predicate<?%20super%20E>))`(`[Predicate](https://developer.android.com/reference/java/util/function/Predicate)`<? super E> filter) ` Removes all of the elements of this collection that satisfy the given predicate.                                                 | | ` abstract boolean`                                                                          | ` `[retainAll](https://developer.android.com/reference/java/util/Collection#retainAll(java.util.Collection<?>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<?> c) ` Retains only the elements in this collection that are contained in the specified collection (optional operation).                                                      | | ` abstract int`                                                                              | ` `[size](https://developer.android.com/reference/java/util/Collection#size())`() ` Returns the number of elements in this collection.                                                                                                                                                                                                                                       | | ` default `[Spliterator](https://developer.android.com/reference/java/util/Spliterator)`<E>` | ` `[spliterator](https://developer.android.com/reference/java/util/Collection#spliterator())`() ` Creates a[Spliterator](https://developer.android.com/reference/java/util/Spliterator)over the elements in this collection.                                                                                                                                                 | | ` default `[Stream](https://developer.android.com/reference/java/util/stream/Stream)`<E>`    | ` `[stream](https://developer.android.com/reference/java/util/Collection#stream())`() ` Returns a sequential`Stream`with this collection as its source.                                                                                                                                                                                                                      | | ` abstract <T> T[]`                                                                          | ` `[toArray](https://developer.android.com/reference/java/util/Collection#toArray(T[]))`(T[] a) ` Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array.                                                                                                                                 | | ` abstract `[Object[]](https://developer.android.com/reference/java/lang/Object)             | ` `[toArray](https://developer.android.com/reference/java/util/Collection#toArray())`() ` Returns an array containing all of the elements in this collection.                                                                                                                                                                                                                | | ` default <T> T[]`                                                                           | ` `[toArray](https://developer.android.com/reference/java/util/Collection#toArray(java.util.function.IntFunction<T[]>))`(`[IntFunction](https://developer.android.com/reference/java/util/function/IntFunction)`<T[]> generator) ` Returns an array containing all of the elements in this collection, using the provided`generator`function to allocate the returned array. | ||
| From interface` `[java.util.Set](https://developer.android.com/reference/java/util/Set)` ` |----------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract boolean`                                                                          | ` `[add](https://developer.android.com/reference/java/util/Set#add(E))`(E e) ` Adds the specified element to this set if it is not already present (optional operation).                                                                                                                                                                                                     | | ` abstract boolean`                                                                          | ` `[addAll](https://developer.android.com/reference/java/util/Set#addAll(java.util.Collection<?%20extends%20E>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<? extends E> c) ` Adds all of the elements in the specified collection to this set if they're not already present (optional operation).                                       | | ` abstract void`                                                                             | ` `[clear](https://developer.android.com/reference/java/util/Set#clear())`() ` Removes all of the elements from this set (optional operation).                                                                                                                                                                                                                               | | ` abstract boolean`                                                                          | ` `[contains](https://developer.android.com/reference/java/util/Set#contains(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` o) ` Returns`true`if this set contains the specified element.                                                                                                                                          | | ` abstract boolean`                                                                          | ` `[containsAll](https://developer.android.com/reference/java/util/Set#containsAll(java.util.Collection<?>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<?> c) ` Returns`true`if this set contains all of the elements of the specified collection.                                                                                        | | ` static <E> `[Set](https://developer.android.com/reference/java/util/Set)`<E>`              | ` `[copyOf](https://developer.android.com/reference/java/util/Set#copyOf(java.util.Collection<?%20extends%20E>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<? extends E> coll) ` Returns an[unmodifiable Set](https://developer.android.com/reference/android/util/ArraySet#unmodifiable)containing the elements of the given Collection. | | ` abstract boolean`                                                                          | ` `[equals](https://developer.android.com/reference/java/util/Set#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` o) ` Compares the specified object with this set for equality.                                                                                                                                             | | ` abstract int`                                                                              | ` `[hashCode](https://developer.android.com/reference/java/util/Set#hashCode())`() ` Returns the hash code value for this set.                                                                                                                                                                                                                                               | | ` abstract boolean`                                                                          | ` `[isEmpty](https://developer.android.com/reference/java/util/Set#isEmpty())`() ` Returns`true`if this set contains no elements.                                                                                                                                                                                                                                            | | ` abstract `[Iterator](https://developer.android.com/reference/java/util/Iterator)`<E>`      | ` `[iterator](https://developer.android.com/reference/java/util/Set#iterator())`() ` Returns an iterator over the elements in this set.                                                                                                                                                                                                                                      | | ` static <E> `[Set](https://developer.android.com/reference/java/util/Set)`<E>`              | ` `[of](https://developer.android.com/reference/java/util/Set#of(E,%20E,%20E))`(E e1, E e2, E e3) ` Returns an unmodifiable set containing three elements.                                                                                                                                                                                                                   | | ` static <E> `[Set](https://developer.android.com/reference/java/util/Set)`<E>`              | ` `[of](https://developer.android.com/reference/java/util/Set#of(E,%20E,%20E,%20E,%20E,%20E,%20E,%20E,%20E))`(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9) ` Returns an unmodifiable set containing nine elements.                                                                                                                                                  | | ` static <E> `[Set](https://developer.android.com/reference/java/util/Set)`<E>`              | ` `[of](https://developer.android.com/reference/java/util/Set#of(E,%20E,%20E,%20E,%20E))`(E e1, E e2, E e3, E e4, E e5) ` Returns an unmodifiable set containing five elements.                                                                                                                                                                                              | | ` static <E> `[Set](https://developer.android.com/reference/java/util/Set)`<E>`              | ` `[of](https://developer.android.com/reference/java/util/Set#of(E,%20E,%20E,%20E,%20E,%20E))`(E e1, E e2, E e3, E e4, E e5, E e6) ` Returns an unmodifiable set containing six elements.                                                                                                                                                                                    | | ` static <E> `[Set](https://developer.android.com/reference/java/util/Set)`<E>`              | ` `[of](https://developer.android.com/reference/java/util/Set#of(E,%20E,%20E,%20E,%20E,%20E,%20E,%20E))`(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8) ` Returns an unmodifiable set containing eight elements.                                                                                                                                                            | | ` static <E> `[Set](https://developer.android.com/reference/java/util/Set)`<E>`              | ` `[of](https://developer.android.com/reference/java/util/Set#of(E[]))`(E... elements) ` Returns an unmodifiable set containing an arbitrary number of elements.                                                                                                                                                                                                             | | ` static <E> `[Set](https://developer.android.com/reference/java/util/Set)`<E>`              | ` `[of](https://developer.android.com/reference/java/util/Set#of())`() ` Returns an unmodifiable set containing zero elements.                                                                                                                                                                                                                                               | | ` static <E> `[Set](https://developer.android.com/reference/java/util/Set)`<E>`              | ` `[of](https://developer.android.com/reference/java/util/Set#of(E,%20E,%20E,%20E,%20E,%20E,%20E,%20E,%20E,%20E))`(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10) ` Returns an unmodifiable set containing ten elements.                                                                                                                                       | | ` static <E> `[Set](https://developer.android.com/reference/java/util/Set)`<E>`              | ` `[of](https://developer.android.com/reference/java/util/Set#of(E,%20E))`(E e1, E e2) ` Returns an unmodifiable set containing two elements.                                                                                                                                                                                                                                | | ` static <E> `[Set](https://developer.android.com/reference/java/util/Set)`<E>`              | ` `[of](https://developer.android.com/reference/java/util/Set#of(E,%20E,%20E,%20E,%20E,%20E,%20E))`(E e1, E e2, E e3, E e4, E e5, E e6, E e7) ` Returns an unmodifiable set containing seven elements.                                                                                                                                                                       | | ` static <E> `[Set](https://developer.android.com/reference/java/util/Set)`<E>`              | ` `[of](https://developer.android.com/reference/java/util/Set#of(E,%20E,%20E,%20E))`(E e1, E e2, E e3, E e4) ` Returns an unmodifiable set containing four elements.                                                                                                                                                                                                         | | ` static <E> `[Set](https://developer.android.com/reference/java/util/Set)`<E>`              | ` `[of](https://developer.android.com/reference/java/util/Set#of(E))`(E e1) ` Returns an unmodifiable set containing one element.                                                                                                                                                                                                                                            | | ` abstract boolean`                                                                          | ` `[remove](https://developer.android.com/reference/java/util/Set#remove(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` o) ` Removes the specified element from this set if it is present (optional operation).                                                                                                                    | | ` abstract boolean`                                                                          | ` `[removeAll](https://developer.android.com/reference/java/util/Set#removeAll(java.util.Collection<?>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<?> c) ` Removes from this set all of its elements that are contained in the specified collection (optional operation).                                                                | | ` abstract boolean`                                                                          | ` `[retainAll](https://developer.android.com/reference/java/util/Set#retainAll(java.util.Collection<?>))`(`[Collection](https://developer.android.com/reference/java/util/Collection)`<?> c) ` Retains only the elements in this set that are contained in the specified collection (optional operation).                                                                    | | ` abstract int`                                                                              | ` `[size](https://developer.android.com/reference/java/util/Set#size())`() ` Returns the number of elements in this set (its cardinality).                                                                                                                                                                                                                                   | | ` default `[Spliterator](https://developer.android.com/reference/java/util/Spliterator)`<E>` | ` `[spliterator](https://developer.android.com/reference/java/util/Set#spliterator())`() ` Creates a`Spliterator`over the elements in this set.                                                                                                                                                                                                                              | | ` abstract `[Object[]](https://developer.android.com/reference/java/lang/Object)             | ` `[toArray](https://developer.android.com/reference/java/util/Set#toArray())`() ` Returns an array containing all of the elements in this set.                                                                                                                                                                                                                              | | ` abstract <T> T[]`                                                                          | ` `[toArray](https://developer.android.com/reference/java/util/Set#toArray(T[]))`(T[] a) ` Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.                                                                                                                                               | ||
| From interface` `[java.lang.Iterable](https://developer.android.com/reference/java/lang/Iterable)` ` |----------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` default void`                                                                              | ` `[forEach](https://developer.android.com/reference/java/lang/Iterable#forEach(java.util.function.Consumer<?%20super%20T>))`(`[Consumer](https://developer.android.com/reference/java/util/function/Consumer)`<? super T> action) ` Performs the given action for each element of the`Iterable`until all elements have been processed or the action throws an exception. | | ` abstract `[Iterator](https://developer.android.com/reference/java/util/Iterator)`<E>`      | ` `[iterator](https://developer.android.com/reference/java/lang/Iterable#iterator())`() ` Returns an iterator over elements of type`T`.                                                                                                                                                                                                                                   | | ` default `[Spliterator](https://developer.android.com/reference/java/util/Spliterator)`<E>` | ` `[spliterator](https://developer.android.com/reference/java/lang/Iterable#spliterator())`() ` Creates a[Spliterator](https://developer.android.com/reference/java/util/Spliterator)over the elements described by this`Iterable`.                                                                                                                                       | ||

## Public constructors

### ArraySet

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

```
public ArraySet ()
```

Create a new empty ArraySet. The default capacity of an array map is 0, and will grow once items are added to it.

<br />

### ArraySet

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

```
public ArraySet (ArraySet<E> set)
```

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

<br />

|        Parameters        ||
|-------|-------------------|
| `set` | `ArraySet` <br /> |

### ArraySet

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

```
public ArraySet (E[] array)
```

Create a new ArraySet with items from the given array

<br />

|                  Parameters                   ||
|---------|--------------------------------------|
| `array` | `E`: This value may be`null`. <br /> |

### ArraySet

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

```
public ArraySet (int capacity)
```

Create a new ArraySet with a given initial capacity.

<br />

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

### ArraySet

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

```
public ArraySet (Collection<? extends E> set)
```

Create a new ArraySet with items from the given collection.

<br />

|         Parameters         ||
|-------|---------------------|
| `set` | `Collection` <br /> |

## Public methods

### add

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

```
public boolean add (E value)
```

Adds the specified object to this set. The set is not modified if it already contains the object.

<br />

|               Parameters                ||
|---------|--------------------------------|
| `value` | `E`: the object to add. <br /> |

|                              Returns                              ||
|-----------|--------------------------------------------------------|
| `boolean` | `true`if this set is modified,`false`otherwise. <br /> |

### addAll

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

```
public boolean addAll (Collection<? extends E> collection)
```

Perform an[add(java.lang.Object)](https://developer.android.com/reference/android/util/ArraySet#add(E))of all values in<var translate="no">collection</var>

<br />

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

|                                  Returns                                   ||
|-----------|-----------------------------------------------------------------|
| `boolean` | `true`if this collection changed as a result of the call <br /> |

### addAll

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

```
public void addAll (ArraySet<? extends E> array)
```

Perform a[add(java.lang.Object)](https://developer.android.com/reference/android/util/ArraySet#add(E))of all values in<var translate="no">array</var>

<br />

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

### clear

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

```
public void clear ()
```

Make the array map empty. All storage is released.

<br />

### contains

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

```
public boolean contains (Object key)
```

Check whether a value exists in the set.

<br />

|                    Parameters                    ||
|-------|-------------------------------------------|
| `key` | `Object`: The value to search for. <br /> |

|                             Returns                             ||
|-----------|------------------------------------------------------|
| `boolean` | Returns true if the value exists, else false. <br /> |

### containsAll

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

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

Determine if the array set contains all of the values 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 set contains a value for every entry in<var translate="no">collection</var>, else returns false. <br /> |

### ensureCapacity

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

```
public void ensureCapacity (int minimumCapacity)
```

Ensure the array map can hold at least<var translate="no">minimumCapacity</var>items.

<br />

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

### equals

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

```
public boolean equals (Object object)
```

Indicates whether some other object is "equal to" this one.

The`equals`method implements an equivalence relation on non-null object references:

- It is*reflexive* : for any non-null reference value`x`,`x.equals(x)`should return`true`.
- It is*symmetric* : for any non-null reference values`x`and`y`,`x.equals(y)`should return`true`if and only if`y.equals(x)`returns`true`.
- It is*transitive* : for any non-null reference values`x`,`y`, and`z`, if`x.equals(y)`returns`true`and`y.equals(z)`returns`true`, then`x.equals(z)`should return`true`.
- It is*consistent* : for any non-null reference values`x`and`y`, multiple invocations of`x.equals(y)`consistently return`true`or consistently return`false`, provided no information used in`equals`comparisons on the objects is modified.
- For any non-null reference value`x`,`x.equals(null)`should return`false`.

An equivalence relation partitions the elements it operates on into*equivalence classes*; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

This implementation returns false if the object is not a set, or if the sets have different sizes. Otherwise, for each value in this set, it checks to make sure the value also exists in the other set. If any value doesn't exist, the method returns false; otherwise, it returns true.

<br />

|                     Parameters                      ||
|----------|-------------------------------------------|
| `object` | `Object`: This value may be`null`. <br /> |

|                                         Returns                                          ||
|-----------|-------------------------------------------------------------------------------|
| `boolean` | `true`if this object is the same as the obj argument;`false`otherwise. <br /> |

### forEach

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

```
public void forEach (Consumer<? super E> action)
```

Performs the given action for all elements in the stored order. This implementation overrides the default implementation to avoid using the[iterator()](https://developer.android.com/reference/android/util/ArraySet#iterator()).

<br />

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

### hashCode

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

```
public int hashCode ()
```

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by[HashMap](https://developer.android.com/reference/java/util/HashMap).

The general contract of`hashCode`is:

- Whenever it is invoked on the same object more than once during an execution of a Java application, the`hashCode`method must consistently return the same integer, provided no information used in`equals`comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
- If two objects are equal according to the[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))method, then calling the`hashCode`method on each of the two objects must produce the same integer result.
- It is*not* required that if two objects are unequal according to the[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))method, then calling the`hashCode`method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.

<br />

<br />

|                     Returns                      ||
|-------|-------------------------------------------|
| `int` | a hash code value for this object. <br /> |

### indexOf

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

```
public int indexOf (Object key)
```

Returns the index of a value in the set.

<br />

|                    Parameters                    ||
|-------|-------------------------------------------|
| `key` | `Object`: The value to search for. <br /> |

|                                       Returns                                       ||
|-------|------------------------------------------------------------------------------|
| `int` | Returns the index of the value if it exists, else a negative integer. <br /> |

### isEmpty

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

```
public boolean isEmpty ()
```

Return true if the array map contains no items.

<br />

|                             Returns                             ||
|-----------|------------------------------------------------------|
| `boolean` | `true`if this collection contains no elements <br /> |

### iterator

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

```
public Iterator<E> iterator ()
```

Return an[Iterator](https://developer.android.com/reference/java/util/Iterator)over all values in the set.

**Note:**this is a fairly inefficient way to access the array contents, it requires generating a number of temporary objects and allocates additional state information associated with the container that will remain for the life of the container.

<br />

<br />

|                                                               Returns                                                                ||
|-----------------------------------------------------------------------------|---------------------------------------------------------|
| [Iterator](https://developer.android.com/reference/java/util/Iterator)`<E>` | an`Iterator`over the elements in this collection <br /> |

### remove

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

```
public boolean remove (Object object)
```

Removes the specified object from this set.

<br />

|                    Parameters                    ||
|----------|----------------------------------------|
| `object` | `Object`: the object to remove. <br /> |

|                              Returns                               ||
|-----------|---------------------------------------------------------|
| `boolean` | `true`if this set was modified,`false`otherwise. <br /> |

### removeAll

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

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

Remove all values in the array set that exist in the given collection.

<br />

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

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

### removeAll

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

```
public boolean removeAll (ArraySet<? extends E> array)
```

Perform a[remove(java.lang.Object)](https://developer.android.com/reference/android/util/ArraySet#remove(java.lang.Object))of all values in<var translate="no">array</var>

<br />

|                               Parameters                                ||
|---------|----------------------------------------------------------------|
| `array` | `ArraySet`: The array whose contents are to be removed. <br /> |

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

### removeAt

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

```
public E removeAt (int index)
```

Remove the key/value mapping at the given index.

For indices outside of the range`0...size()-1`, the behavior is undefined for apps targeting[Build.VERSION_CODES.P](https://developer.android.com/reference/android/os/Build.VERSION_CODES#P)and earlier, and an[ArrayIndexOutOfBoundsException](https://developer.android.com/reference/java/lang/ArrayIndexOutOfBoundsException)is thrown for apps targeting[Build.VERSION_CODES.Q](https://developer.android.com/reference/android/os/Build.VERSION_CODES#Q)and later.

<br />

<br />

|                                                                    Parameters                                                                    ||
|---------|-----------------------------------------------------------------------------------------------------------------------------------------|
| `index` | `int`: The desired index, must be between 0 and[size()](https://developer.android.com/reference/android/util/ArraySet#size())-1. <br /> |

|                           Returns                            ||
|-----|---------------------------------------------------------|
| `E` | Returns the value that was stored at this index. <br /> |

### removeIf

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

```
public boolean removeIf (Predicate<? super E> filter)
```

Removes all values that satisfy the predicate. This implementation avoids using the[iterator()](https://developer.android.com/reference/android/util/ArraySet#iterator()).

<br />

|                                       Parameters                                        ||
|----------|-------------------------------------------------------------------------------|
| `filter` | `Predicate`: A predicate which returns true for elements to be removed <br /> |

|                       Returns                        ||
|-----------|-------------------------------------------|
| `boolean` | `true`if any elements were removed <br /> |

### retainAll

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

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

Remove all values in the array set that do**not**exist in the given collection.

<br />

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

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

### size

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

```
public int size ()
```

Return the number of items in this array map.

<br />

|                         Returns                         ||
|-------|--------------------------------------------------|
| `int` | the number of elements in this collection <br /> |

### toArray

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

```
public T[] toArray (T[] array)
```

Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. If the collection fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this collection.

If this collection fits in the specified array with room to spare (i.e., the array has more elements than this collection), the element in the array immediately following the end of the collection is set to`null`. (This is useful in determining the length of this collection*only* if the caller knows that this collection does not contain any`null`elements.)

If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.

<br />

|                                                                                           Parameters                                                                                            ||
|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `array` | `T`: the array into which the elements of this collection are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose. <br /> |

|                                 Returns                                  ||
|-------|-------------------------------------------------------------------|
| `T[]` | an array containing all of the elements in this collection <br /> |

### toArray

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

```
public Object[] toArray ()
```

Returns an array containing all of the elements in this collection. If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order. The returned array's[runtime component type](https://developer.android.com/reference/java/lang/Class#getComponentType())is`Object`.

The returned array will be "safe" in that no references to it are maintained by this collection. (In other words, this method must allocate a new array even if this collection is backed by an array). The caller is thus free to modify the returned array.

<br />

|                                                                                                                   Returns                                                                                                                   ||
|----------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Object[]](https://developer.android.com/reference/java/lang/Object) | an array, whose[type](https://developer.android.com/reference/java/lang/Class#getComponentType())is`Object`, containing all of the elements in this collection <br /> |

### toString

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

```
public String toString ()
```

Returns a string representation of the object.

This implementation composes a string by iterating over its values. If this set contains itself as a value, the string "(this Set)" will appear in its place.

<br />

|                                                      Returns                                                      ||
|--------------------------------------------------------------------|-----------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | a string representation of the object. <br /> |

### valueAt

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

```
public E valueAt (int index)
```

Return the value at the given index in the array.

For indices outside of the range`0...size()-1`, the behavior is undefined for apps targeting[Build.VERSION_CODES.P](https://developer.android.com/reference/android/os/Build.VERSION_CODES#P)and earlier, and an[ArrayIndexOutOfBoundsException](https://developer.android.com/reference/java/lang/ArrayIndexOutOfBoundsException)is thrown for apps targeting[Build.VERSION_CODES.Q](https://developer.android.com/reference/android/os/Build.VERSION_CODES#Q)and later.

<br />

<br />

|                                                                    Parameters                                                                    ||
|---------|-----------------------------------------------------------------------------------------------------------------------------------------|
| `index` | `int`: The desired index, must be between 0 and[size()](https://developer.android.com/reference/android/util/ArraySet#size())-1. <br /> |

|                         Returns                          ||
|-----|-----------------------------------------------------|
| `E` | Returns the value stored at the given index. <br /> |