All Packages Class Hierarchy This Package Previous Next Index
Class java.util.ArraySet
java.lang.Object
|
+----java.util.AbstractCollection
|
+----java.util.AbstractSet
|
+----java.util.ArraySet
- public class ArraySet
- extends AbstractSet
- implements Set, Cloneable, Serializable
This class implements the Set interface, backed by an ArrayList. It is
designed to offer good performance for very small Sets, especially those
that are frequently created and destroyed. The performance will be
extremely bad for large Sets: ArraySet provides linear time
performance for the basic operations (add, remove and contains). This Set
permit all elements, including null.
Note that this implementation is not synchronized. If
multiple threads access an ArraySet concurrently, and at least one of the
threads modifies the ArraySet, it must be synchronized externally.
This is typically accomplished by synchronizing on some object that
naturally encapsulates the ArraySet. If no such object exists, the ArraySet
should be "wrapped" using the Collections.synchronizedSet method. This is
best done at creation time, to prevent accidental unsynchronized access to
the ArraySet:
Set s = Collections.synchronizedSet(new ArraySet(...));
The Iterators returned by ArraySet's iterator method are
fail-fast: if the HashSet is modified at any time after the
Iterator is created, in any way except through the Iterator's own remove
method, the Iterator will throw a ConcurrentModificationException. Thus,
in the face of concurrent modification, the Iterator fails quickly and
cleanly, rather than risking arbitrary, non-deterministic behavior at an
undetermined time in the future.
- Since:
- JDK1.2
- See Also:
- Collection, Set, HashSet, Collections.synchronizedSet, ArrayList
ArraySet()
- Constructs a new, empty ArraySet; the backing ArrayList has default
initial capacity and capacity increment.
ArraySet(Collection)
- Constructs a new ArraySet containing the elements in the specified
Collection.
ArraySet(int)
- Constructs a new, empty ArraySet; the backing ArrayList has the
specified initial capacity and default capacity increment.
add(Object)
- Adds the specified element to this Set if it is not already present.
clear()
- Removes all of the elements from this Set.
clone()
- Returns a shallow copy of this ArraySet.
contains(Object)
- Returns true if this ArraySet contains the specified element.
isEmpty()
- Returns true if this ArraySet contains no elements.
iterator()
- Returns an Iterator over the elements in this ArraySet.
remove(Object)
- Removes the given element from this Set if it is present.
size()
- Returns the number of elements in this ArraySet (its cardinality).
ArraySet
public ArraySet()
- Constructs a new, empty ArraySet; the backing ArrayList has default
initial capacity and capacity increment.
ArraySet
public ArraySet(Collection c)
- Constructs a new ArraySet containing the elements in the specified
Collection. The backing ArrayList has default initial capacity and
capacity increment.
- Throws:
NullPointerException
- the specified collection is null.
ArraySet
public ArraySet(int initialCapacity)
- Constructs a new, empty ArraySet; the backing ArrayList has the
specified initial capacity and default capacity increment.
- Parameters:
- initialCapacity - the initial capacity of the ArrayList.
iterator
public Iterator iterator()
- Returns an Iterator over the elements in this ArraySet. The elements
are returned in the order they were added.
- Overrides:
- iterator in class AbstractCollection
size
public int size()
- Returns the number of elements in this ArraySet (its cardinality).
- Overrides:
- size in class AbstractCollection
isEmpty
public boolean isEmpty()
- Returns true if this ArraySet contains no elements.
- Overrides:
- isEmpty in class AbstractCollection
contains
public boolean contains(Object o)
- Returns true if this ArraySet contains the specified element.
- Overrides:
- contains in class AbstractCollection
add
public boolean add(Object o)
- Adds the specified element to this Set if it is not already present.
- Parameters:
- o - element to be added to this Set.
- Returns:
- true if the Set did not already contain the specified element.
- Overrides:
- add in class AbstractCollection
remove
public boolean remove(Object o)
- Removes the given element from this Set if it is present.
- Parameters:
- o - object to be removed from this Set, if present.
- Returns:
- true if the Set contained the specified element.
- Overrides:
- remove in class AbstractCollection
clear
public void clear()
- Removes all of the elements from this Set.
- Overrides:
- clear in class AbstractCollection
clone
public Object clone()
- Returns a shallow copy of this ArraySet. (The elements themselves
are not cloned.)
- Overrides:
- clone in class Object
All Packages Class Hierarchy This Package Previous Next Index
Submit a bug or feature