ArraySet
public
final
class
ArraySet
extends Object
implements
Collection<E>,
Set<E>
java.lang.Object | |
↳ | android.support.v4.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.
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<E> set)
Create a new ArraySet with the mappings from the given |
Public methods | |
---|---|
boolean
|
add(E value)
Adds the specified object to this set. |
boolean
|
addAll(Collection<? extends E> collection)
Perform an |
void
|
addAll(ArraySet<? extends E> array)
Perform a |
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)
This implementation returns false if the object is not a set, or if the sets have different sizes. |
int
|
hashCode()
|
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 |
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( |