public class ArraySet<E> extends Object implements Set<E>, Serializable
A Set
which is backed by a simple array of elements. This provides
all the behaviors of a set backed by an array, thus insert and remove
operations are always O(n) time to check for uniqueness. This should only be
used for sets which are known to be mostly empty or to contain only a handful
of elements.
The primary use of this set is for those cases where small sets exists and will not be changed. The savings in memory is significant compared to hash sets which may contain many empty buckets.
Constructor and Description |
---|
ArraySet() |
ArraySet(ArrayList<E> initialList) |
ArraySet(Collection<E> initialElements) |
ArraySet(Collection<E> initialElements,
E... initialElements2) |
ArraySet(E... initialElements) |
ArraySet(int size) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(E e) |
boolean |
addAll(Collection<? extends E> otherCollection) |
boolean |
addAll(E... elements) |
List<E> |
asList() |
void |
clear() |
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> c) |
boolean |
equals(Object obj) |
int |
hashCode() |
boolean |
isEmpty() |
Iterator<E> |
iterator() |
boolean |
remove(Object o) |
boolean |
removeAll(Collection<?> c) |
boolean |
retainAll(Collection<?> c) |
int |
size() |
Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
String |
toString() |
ArraySet<E> |
trimToSize() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
spliterator
parallelStream, removeIf, stream
public ArraySet(Collection<E> initialElements)
public ArraySet(int size)
public ArraySet()
public ArraySet(E... initialElements)
public ArraySet(Collection<E> initialElements, E... initialElements2)
public boolean add(E e)
public boolean addAll(Collection<? extends E> otherCollection)
public boolean addAll(E... elements)
public void clear()
public boolean contains(Object o)
public boolean containsAll(Collection<?> c)
containsAll
in interface Collection<E>
containsAll
in interface Set<E>
public boolean isEmpty()
public boolean remove(Object o)
public boolean removeAll(Collection<?> c)
public boolean retainAll(Collection<?> c)
public int size()
public Object[] toArray()
public <T> T[] toArray(T[] a)
public boolean equals(Object obj)
public int hashCode()
Copyright © 2016. All rights reserved.