capacity-restricted deque is full. Second, methods such as offerFirst( ) and offerLast( ) return
false if the element can not be added.
The Collection Classes
Now that you are familiar with the collection interfaces, you are ready to examine the standard
classes that implement them. Some of the classes provide full implementations that can be
used as-is. Others are abstract, providing skeletal implementations that are used as starting
points for creating concrete collections. None of the collection classes are synchronized, but
as you will see later in this chapter, it is possible to obtain synchronized versions.
The standard collection classes are summarized in the following table:
Implements most of the Collection inter face.
Extends AbstractCollection and implements most of the List inter face.
Extends AbstractCollection and implements par ts of the Queue inter face.
Extends AbstractList for use by a collection that uses sequential rather than random
access of its elements.
Implements a linked list by extending AbstractSequentialList.
Implements a dynamic array by extending AbstractList.
Implements a dynamic double-ended queue by extending AbstractCollection and
implementing the Deque inter face. (Added by Java SE 6.)
Extends AbstractCollection and implements most of the Set inter face.
Extends AbstractSet for use with enum elements.
Extends AbstractSet for use with a hash table.
Extends HashSet to allow inser tion-order iterations.
Extends AbstractQueue to suppor t a priority-based queue.
Implements a set stored in a tree. Extends AbstractSet.
The following sections examine the concrete collection classes and illustrate their use.
NOTE  In addition to the collection classes, several legacy classes, such as Vector, Stack, and
Hashtable, have been reengineered to support collections. These are examined later in this chapter.
The ArrayList Class
The ArrayList class extends AbstractList and implements the List interface. ArrayList is a
generic class that has this declaration:
class ArrayList<E>
Here, E specifies the type of objects that the list will hold.
ArrayList supports dynamic arrays that can grow as needed. In Java, standard arrays are
of a fixed length. After arrays are created, they cannot grow or shrink, which means that you
must know in advance how many elements an array will hold. But, sometimes, you may not
know until run time precisely how large an array you need. To handle this situation, the
Collections Framework defines ArrayList. In essence, an ArrayList is a variable-length array
of object references. That is, an ArrayList can dynamically increase or decrease in size. Array
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks