# Print output for @column tags ?>
Developers

- Design
- Develop
- Distribute

Developer Console

## Most visited

## Recently visited

## Results for

Summary: Ctors | Methods | Inherited Methods

# ArraySet

`public final class ArraySet`
`extends Object` `implements Collection<E>, Set<E>`

java.lang.Object
↳ | android.util.ArraySet<E>

ArraySet is a generic set data structure that is designed to be more memory efficient than a traditional `HashSet`. The design is very similar to `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.

## Summary

### Public constructors
`ArraySet()` Create a new empty ArraySet.
`ArraySet(int capacity)` Create a new ArraySet with a given initial capacity.
`ArraySet(ArraySet<E> set)` Create a new ArraySet with the mappings from the given ArraySet.
`ArraySet(Collection<? extends E> set)` Create a new ArraySet with items from the given collection.
`ArraySet(E[] array)` Create a new ArraySet with items from the given array

### Public methods
`boolean` | `add(E value)` Adds the specified object to this set.
`boolean` | `addAll(Collection<? extends E> collection)` Perform an `add(java.lang.Object)` of all values in collection
`void` | `addAll(ArraySet<? extends E> array)` Perform a `add(java.lang.Object)` of all values in array
`void` | `clear()` Make the array map empty.
`boolean` | `contains(Object key)` Check whether a value exists in the set.
`boolean` | `containsAll(Collection<?> collection)` Determine if the array set contains all of the values in the given collection.
`void` | `ensureCapacity(int minimumCapacity)` Ensure the array map can hold at least minimumCapacity items.
`boolean` | `equals(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.
`int` | `hashCode()` Returns a hash code value for the object.
`int` | `indexOf(Object key)` Returns the index of a value in the set.
`boolean` | `isEmpty()` Return true if the array map contains no items.
`Iterator<E>` | `iterator()` Return an `Iterator` over all values in the set.
`boolean` | `remove(Object object)` Removes the specified object from this set.
`boolean` | `removeAll(Collection<?> collection)` Remove all values in the array set that exist in the given collection.
`boolean` | `removeAll(ArraySet<? extends E> array)` Perform a `remove(java.lang.Object)` of all values in array
`E` | `removeAt(int index)` Remove the key/value mapping at the given index.
`boolean` | `removeIf(Predicate<? super E> filter)` Removes all values that satisfy the predicate.
`boolean` | `retainAll(Collection<?> collection)` Remove all values in the array set that do not exist in the given collection.
`int` | `size()` Return the number of items in this array map.
`<T> 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.
`Object[]` | `toArray()` Returns an array containing all of the elements in this collection.
`String` | `toString()` Returns a string representation of the object. This implementation composes a string by iterating over its values.
`E` | `valueAt(int index)` Return the value at the given index in the array.

### Inherited methods
From class `java.lang.Object`
`Object` | `clone()` Creates and returns a copy of this object.
`boolean` | `equals(Object obj)` Indicates whether some other object is "equal to" this one.
`void` | `finalize()` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
`final Class<?>` | `getClass()` Returns the runtime class of this `Object`.
`int` | `hashCode()` Returns a hash code value for the object.
`final void` | `notify()` Wakes up a single thread that is waiting on this object's monitor.
`final void` | `notifyAll()` Wakes up all threads that are waiting on this object's monitor.
`String` | `toString()` Returns a string representation of the object.
`final void` | `wait(long timeout, int nanos)` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
`final void` | `wait(long timeout)` Causes the current thread to wait until either another thread invokes the `notify()` method or the `notifyAll()` method for this object, or a specified amount of time has elapsed.
`final void` | `wait()` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object.
From interface `java.util.Collection`
`abstract boolean` | `add(E e)` Ensures that this collection contains the specified element (optional operation).
`abstract boolean` | `addAll(Collection<? extends E> c)` Adds all of the elements in the specified collection to this collection (optional operation).
`abstract void` | `clear()` Removes all of the elements from this collection (optional operation).
`abstract boolean` | `contains(Object o)` Returns `true` if this collection contains the specified element.
`abstract boolean` | `containsAll(Collection<?> c)` Returns `true` if this collection contains all of the elements in the specified collection.
`abstract boolean` | `equals(Object o)` Compares the specified object with this collection for equality.
`abstract int` | `hashCode()` Returns the hash code value for this collection.
`abstract boolean` | `isEmpty()` Returns `true` if this collection contains no elements.
`abstract Iterator<E>` | `iterator()` Returns an iterator over the elements in this collection.
`default Stream<E>` | `parallelStream()` Returns a possibly parallel `Stream` with this collection as its source.
`abstract boolean` | `remove(Object o)` Removes a single instance of the specified element from this collection, if it is present (optional operation).
`abstract boolean` | `removeAll(Collection<?> c)` Removes all of this collection's elements that are also contained in the specified collection (optional operation).
`default boolean` | `removeIf(Predicate<? super E> filter)` Removes all of the elements of this collection that satisfy the given predicate.
`abstract boolean` | `retainAll(Collection<?> c)` Retains only the elements in this collection that are contained in the specified collection (optional operation).
`abstract int` | `size()` Returns the number of elements in this collection.
`default Spliterator<E>` | `spliterator()` Creates a `Spliterator` over the elements in this collection.
`default Stream<E>` | `stream()` Returns a sequential `Stream` with this collection as its source.
`abstract <T> T[]` | `toArray(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[]` | `toArray()` Returns an array containing all of the elements in this collection.
From interface `java.util.Set`
`abstract boolean` | `add(E e)` Adds the specified element to this set if it is not already present (optional operation).
`abstract boolean` | `addAll(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()` Removes all of the elements from this set (optional operation).
`abstract boolean` | `contains(Object o)` Returns `true` if this set contains the specified element.
`abstract boolean` | `containsAll(Collection<?> c)` Returns `true` if this set contains all of the elements of the specified collection.
`static <E> Set<E>` | `copyOf(Collection<? extends E> coll)` Returns an unmodifiable Set containing the elements of the given Collection.
`abstract boolean` | `equals(Object o)` Compares the specified object with this set for equality.
`abstract int` | `hashCode()` Returns the hash code value for this set.
`abstract boolean` | `isEmpty()` Returns `true` if this set contains no elements.
`abstract Iterator<E>` | `iterator()` Returns an iterator over the elements in this set.
`static <E> Set<E>` | `of(E e1, E e2, E e3)` Returns an immutable set containing three elements.
`static <E> Set<E>` | `of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9)` Returns an immutable set containing nine elements.
`static <E> Set<E>` | `of(E e1, E e2, E e3, E e4, E e5)` Returns an immutable set containing five elements.
`static <E> Set<E>` | `of(E e1, E e2, E e3, E e4, E e5, E e6)` Returns an immutable set containing six elements.
`static <E> Set<E>` | `of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8)` Returns an immutable set containing eight elements.
`static <E> Set<E>` | `of()` Returns an immutable set containing zero elements.
`static <E> Set<E>` | `of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10)` Returns an immutable set containing ten elements.
`static <E> Set<E>` | `of(E e1, E e2)` Returns an immutable set containing two elements.
`static <E> Set<E>` | `of(E... elements)` Returns an immutable set containing an arbitrary number of elements.
`static <E> Set<E>` | `of(E e1, E e2, E e3, E e4, E e5, E e6, E e7)` Returns an immutable set containing seven elements.
`static <E> Set<E>` | `of(E e1, E e2, E e3, E e4)` Returns an immutable set containing four elements.
`static <E> Set<E>` | `of(E e1)` Returns an immutable set containing one element.
`abstract boolean` | `remove(Object o)` Removes the specified element from this set if it is present (optional operation).
`abstract boolean` | `removeAll(Collection<?> c)` Removes from this set all of its elements that are contained in the specified collection (optional operation).
`abstract boolean` | `retainAll(Collection<?> c)` Retains only the elements in this set that are contained in the specified collection (optional operation).
`abstract int` | `size()` Returns the number of elements in this set (its cardinality).
`default Spliterator<E>` | `spliterator()` Creates a `Spliterator` over the elements in this set.
`abstract Object[]` | `toArray()` Returns an array containing all of the elements in this set.
`abstract <T> T[]` | `toArray(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`
`default void` | `forEach(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<E>` | `iterator()` Returns an iterator over elements of type `T`.
`default Spliterator<E>` | `spliterator()` Creates a `Spliterator` over the elements described by this `Iterable`.

## Public constructors

### ArraySet

    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.

### ArraySet

    public ArraySet (int capacity)

Create a new ArraySet with a given initial capacity.

Parameters
`capacity` | `int`

### ArraySet

    public ArraySet (ArraySet<E> set)

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

Parameters
`set` | `ArraySet`

### ArraySet

    public ArraySet (Collection<? extends E> set)

Create a new ArraySet with items from the given collection.

Parameters
`set` | `Collection`

### ArraySet

    public ArraySet (E[] array)

Create a new ArraySet with items from the given array

Parameters
`array` | `E`: This value may be `null`.

## Public methods

### add

    public boolean add (E value)

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

Parameters
`value` | `E`: the object to add.

Returns
`boolean` | `true` if this set is modified, `false` otherwise.

### addAll

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

Perform an `add(java.lang.Object)` of all values in collection

Parameters
`collection` | `Collection`: The collection whose contents are to be retrieved.

Returns
`boolean` | `true` if this collection changed as a result of the call

### addAll

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

Perform a `add(java.lang.Object)` of all values in array

Parameters
`array` | `ArraySet`: The array whose contents are to be retrieved.

### clear

    public void clear ()

Make the array map empty. All storage is released.

### contains

    public boolean contains (Object key)

Check whether a value exists in the set.

Parameters
`key` | `Object`: The value to search for.

Returns
`boolean` | Returns true if the value exists, else false.

### containsAll

    public boolean containsAll (Collection<?> collection)

Determine if the array set contains all of the values in the given collection.

Parameters
`collection` | `Collection`: The collection whose contents are to be checked against.

Returns
`boolean` | Returns true if this array set contains a value for every entry in collection, else returns false.

### ensureCapacity

    public void ensureCapacity (int minimumCapacity)

Ensure the array map can hold at least minimumCapacity items.

Parameters
`minimumCapacity` | `int`

### equals

    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`.

The `equals` method for class `Object` implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values `x` and `y`, this method returns `true` if and only if `x` and `y` refer to the same object (`x == y` has the value `true`).

Note that it is generally necessary to override the `hashCode` method whenever this method is overridden, so as to maintain the general contract for the `hashCode` method, which states that equal objects must have equal hash codes.

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.

Parameters
`object` | `Object`: This value may be `null`.

Returns
`boolean` | `true` if this object is the same as the obj argument; `false` otherwise.

### hashCode

    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`.

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(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(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.

As much as is reasonably practical, the hashCode method defined by class `Object` does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the Java™ programming language.)

Returns
`int` | a hash code value for this object.

### indexOf

    public int indexOf (Object key)

Returns the index of a value in the set.

Parameters
`key` | `Object`: The value to search for.

Returns
`int` | Returns the index of the value if it exists, else a negative integer.

### isEmpty

    public boolean isEmpty ()

Return true if the array map contains no items.

Returns
`boolean` | `true` if this collection contains no elements

### iterator

    public Iterator<E> iterator ()

Return an `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.

Returns
`Iterator<E>` | an `Iterator` over the elements in this collection

### remove

    public boolean remove (Object object)

Removes the specified object from this set.

Parameters
`object` | `Object`: the object to remove.

Returns
`boolean` | `true` if this set was modified, `false` otherwise.

### removeAll

    public boolean removeAll (Collection<?> collection)

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

Parameters
`collection` | `Collection`: The collection whose contents are to be used to remove values.

Returns
`boolean` | Returns true if any values were removed from the array set, else false.

### removeAll

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

Perform a `remove(java.lang.Object)` of all values in array

Parameters
`array` | `ArraySet`: The array whose contents are to be removed.

Returns
`boolean` |

### removeAt

    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` and earlier, and an `ArrayIndexOutOfBoundsException` is thrown for apps targeting `Build.VERSION_CODES.Q` and later.

Parameters
`index` | `int`: The desired index, must be between 0 and `size()`-1.

Returns
`E` | Returns the value that was stored at this index.

### removeIf

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

Removes all values that satisfy the predicate. This implementation avoids using the `iterator()`.

Parameters
`filter` | `Predicate`: A predicate which returns true for elements to be removed

Returns
`boolean` | `true` if any elements were removed

### retainAll

    public boolean retainAll (Collection<?> collection)

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

Parameters
`collection` | `Collection`: The collection whose contents are to be used to determine which values to keep.

Returns
`boolean` | Returns true if any values were removed from the array set, else false.

### size

    public int size ()

Return the number of items in this array map.

Returns
`int` | the number of elements in this collection

### toArray

    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.

Like the `toArray()` method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs.

Suppose `x` is a collection known to contain only strings. The following code can be used to dump the collection into a newly allocated array of `String`:

         String[] y = x.toArray(new String[0]);

Note that `toArray(new Object[0])` is identical in function to `toArray()`.

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.

Returns
`T[]` | an array containing all of the elements in this collection

### toArray

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

This method acts as bridge between array-based and collection-based APIs.

Returns
`Object[]` | an array containing all of the elements in this collection

### toString

    public String toString ()

Returns a string representation of the object. In general, the `toString` method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The `toString` method for class `Object` returns a string consisting of the name of the class of which the object is an instance, the at-sign character ``@`', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

>      getClass().getName() + '@' + Integer.toHexString(hashCode())

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.

Returns
`String` | a string representation of the object.

### valueAt

    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` and earlier, and an `ArrayIndexOutOfBoundsException` is thrown for apps targeting `Build.VERSION_CODES.Q` and later.

Parameters
`index` | `int`: The desired index, must be between 0 and `size()`-1.

Returns
`E` | Returns the value stored at the given index.

Full name *
Email address *
Company / developer name
One of your Play Store app URLs *
Which best describes your business:*
Apps
Games
Apps & Games
*
*