Java Reference
In-Depth Information
TreeSet: A basic implementation of the SortedSet interface. Elements in a
TreeSet will be ordered based on its comparator. The default comparator or-
ders elements based on their natural order, but you can override this behavior
with your own comparator.
A word of caution about the Set collection type . The Set interface defines good se-
mantics that allow a program to add and remove elements from the collection, but
there is no reliable way to manage elements that have changed while they are part
of a set. This is because the modification is assigned to the element itself, not the
collection (that is, the collection doesn't see the modification). The proper se-
quence in this case is to get the element, remove it from the set, modify it, and then
add it into the set. To extend this programming model to the COBOL file process-
ing analogy, you would need to read in the record, modify it, delete the record, and
then write the record.
AbstractSequentialList: The basic implementation of the List interface, appro-
priate for sequential access to the members of the list. This class is provided in
order to simplify the task of a developer who wishes to implement a custom list
collection, one that supports sequential access (for example, a LinkedList ).
LinkedList: The LinkedList implementation of the List interface. This uses
many of the methods provided by the AbstractSequentialList class. It also
adds methods to conveniently add, delete, and retrieve elements from the be-
ginning or end of a list. LinkedLists are most appropriate when you want to
optimize write performance, compared to read performance.
I TERATORS
Iterators are objects that support sequential access to the elements in a collection.
The iterators() method of Vector and ArrayList returns an Iterator object.
Iterator iterator = errorMsgsVector. iterator ();
while (iterator.hasNext()) {
ErrorMsg myErrorMsg = (ErrorMsg ) iterator.next ();
}
To obtain an iterator for a HashMap or Hashtable , you must obtain a reference to
the iterator for either the values or the keys. Once you have the one you want, you
can then use it to iterate either of them.
Search WWH ::




Custom Search