THE Java™ Programming Language, Fourth Edition

(Jeff_L) #1
Collection<E> The root interface for collections. Provides such methods as add, remove,
size, and toArray.


Set<E> A collection in which no duplicate elements can be present, and whose elements are not
necessarily stored in any particular order (extends Collection<E>).



  • SortedSet A set whose elements are sorted (extends Set).
    List A collection whose elements stay in a particular order unless the list is modified (extends
    Collection). This is a general use of the word "list" and does not necessarily mean "linked
    list," although that is one possible implementation.



Queue<E> A collection with an implied ordering in its elements (extends Collection<E>).
Every queue has a head element that is the target of specific operations like peek and poll.


Map<K,V> A mapping from keys to at most one value each. (Map does not extend Collection,
although the concepts meaningful to both maps and collections are represented by methods of the
same names, and maps can be viewed as collections.)



  • SortedMap<K,V> A map whose keys are sorted (extends Map<K,V>).
    Iterator An interface for objects that return elements from a collection one at a time. This is
    the type of object returned by the method Iterable.iterator.



ListIterator<E> An iterator for List objects that adds useful List-related methods. This is
the type of object returned by List.listIterator.


Iterable<E> An object that provides an Iterator and so can be used in an enhanced for
statement. Although defined in the java.lang package, this is considered part of the collection
framework because the vast majority of standard iterable types are collections.


Figure 21-1. Type Trees for Concrete Collections in java.util

The interfaces SortedSet and SortedMap guarantee that iteration through the elements is done in sorted
order. You will learn how to define an order for objects later in this chapter.

Free download pdf