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

Constructor Index

 o ArraySet()
Constructs a new, empty ArraySet; the backing ArrayList has default initial capacity and capacity increment.
 o ArraySet(Collection)
Constructs a new ArraySet containing the elements in the specified Collection.
 o ArraySet(int)
Constructs a new, empty ArraySet; the backing ArrayList has the specified initial capacity and default capacity increment.

Method Index

 o add(Object)
Adds the specified element to this Set if it is not already present.
 o clear()
Removes all of the elements from this Set.
 o clone()
Returns a shallow copy of this ArraySet.
 o contains(Object)
Returns true if this ArraySet contains the specified element.
 o isEmpty()
Returns true if this ArraySet contains no elements.
 o iterator()
Returns an Iterator over the elements in this ArraySet.
 o remove(Object)
Removes the given element from this Set if it is present.
 o size()
Returns the number of elements in this ArraySet (its cardinality).

Constructors

 o ArraySet
public ArraySet()
Constructs a new, empty ArraySet; the backing ArrayList has default initial capacity and capacity increment.

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

Methods

 o 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
 o size
public int size()
Returns the number of elements in this ArraySet (its cardinality).

Overrides:
size in class AbstractCollection
 o isEmpty
public boolean isEmpty()
Returns true if this ArraySet contains no elements.

Overrides:
isEmpty in class AbstractCollection
 o contains
public boolean contains(Object o)
Returns true if this ArraySet contains the specified element.

Overrides:
contains in class AbstractCollection
 o 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
 o 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
 o clear
public void clear()
Removes all of the elements from this Set.

Overrides:
clear in class AbstractCollection
 o 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