Java Reference
In-Depth Information
NavigableSet
TreeSet
SortedSet
Set
AbstractSet
HashSet
LinkedHashSet
AbstractCollection
Collection
Vector
Stack
AbstractList
List
ArrayList
AbstractSequentialList
LinkedList
Deque
Queue
AbstractQueue
PriorityQueue
Interfaces
Abstract Classes
Concrete Classes
F IGURE 20.1
A collection is a container that stores objects.
a concrete class that extends the abstract class rather implements all the methods in
the interface. The abstract classes such as AbstractCollection are provided for
convenience. For this reason, they are called convenience abstract classes .
convenience abstract class
The Collection interface is the root interface for manipulating a collection of objects. Its
public methods are listed in FigureĀ  20.2. The AbstractCollection class provides partial
implementation for the Collection interface. It implements all the methods in Collection
except the add , size , and iterator methods. These are implemented in appropriate concrete
subclasses.
The Collection interface provides the basic operations for adding and removing elements
in a collection. The add method adds an element to the collection. The addAll method adds
all the elements in the specified collection to this collection. The remove method removes an
element from the collection. The removeAll method removes the elements from this collec-
tion that are present in the specified collection. The retainAll method retains the elements
in this collection that are also present in the specified collection. All these methods return
boolean . The return value is true if the collection is changed as a result of the method
execution. The clear() method simply removes all the elements from the collection.
basic operations
Note
The methods addAll , removeAll , and retainAll are similar to the set union,
difference, and intersection operations.
set operations
The Collection interface provides various query operations. The size method returns
the number of elements in the collection. The contains method checks whether the collec-
tion contains the specified element. The containsAll method checks whether the collection
contains all the elements in the specified collection. The isEmpty method returns true if the
collection is empty.
The Collection interface provides the toArray() method, which returns an array rep-
resentation for the collection.
query operations
Design Guide
Some of the methods in the Collection interface cannot be implemented
in the concrete subclass. In this case, the method would throw java.lang
 
 
Search WWH ::




Custom Search