Java Reference
In-Depth Information
Method
Description
set(Object obj)
Replaces the last object retrieved by a call to next() or
previous() . If neither next() nor previous() have been
called, or add() or remove() have been called most recently, an
IllegalStateException will be thrown. If the set() operation
is not supported for this collection an
UnsupportedOperationException will be thrown. If the class
of the reference passed as an argument prevents the object being
stored in the collection, a ClassCastException will be thrown. If
some other characteristic of the argument prevents it being stored in
the collection, an IllegalArgumentException will be thrown.
Now we know about iterators we need to find out a bit about the collection classes themselves in order
to make use of them.
Collection Classes
You have a total of thirteen classes in java.util that you can use to manage collections of objects,
and they support collections that are sets, lists, or maps, as follows:
Class
Description
Sets:
HashSet
An implementation of a set that uses HashMap under the
covers. Although a set is by definition unordered, there has
to be some way to find an object reasonably efficiently. The
use of a HashMap object to implement the set enables store
and retrieve operations to be done in a constant time.
TreeSet
An implementation of a set that orders the objects in the set
in ascending sequence. This means that an iterator obtained
from a TreeSet object will provide the objects in ascending
sequence. The TreeSet classes use a TreeMap under the
covers.
LinkedHashSet
Implements a set using a hash table with all the entries linked
in a doubly-linked list. This class can be used to make a copy
of any set such that iteration ordering is preserved -
something that does not apply to a HashSet .
Table continued on following page
Search WWH ::




Custom Search