Java Reference
In-Depth Information
These objectives are Section 6 of the SCJP exam objectives.
The exam tests your knowledge of the Collections API,
including the use of generics. This chapter covers all of these
topics in detail.
Overview of Collections
A
collection
is a group of objects contained in a single element. Examples of collections
include an array of integers, a vector of strings, or a hash map of vehicles. The
Java
Collections Framework
is a unifi ed set of classes and interfaces defi ned in the
java.util
package for storing collections. For the exam, you need to understand the different types
of collections in the Collections Framework, including lists, maps, and sets. You need
to recognize which collection to use given a specifi c scenario. The exam also tests your
knowledge of the
Comparable
interface and the difference between
==
and the
equals
method. This section discusses all of these topics, starting with a discussion on the
collections interfaces, which provide the foundation of the Collections Framework.
The Collections Interfaces
The
java.util
package contains a group of interfaces referred to as the
collections
interfaces
to represent the various types of collections. The root interface of the collections
interfaces is
Collection
. There are different types of collections, and the subinterfaces of
Collection
refl ect these various types of collections, as follows:
Lists
A
list
is an ordered collection of elements that allows duplicate entries. Lists
implement the
List
interface, and elements in a list can be accessed by an integer index.
Sets
A
set
is a collection that does not allow duplicate entries. Sets implement the
Set
interface.
Queues
A
queue
is a collection that orders its elements in a specifi c order for processing.
A typical queue processes its elements in a fi rst-in, fi rst-out (FIFO) fashion, but other
ordering is possible. Queues implement the
Queue
interface.
Maps
A
map
is a collection that maps keys to values, with no duplicate keys allowed.
The elements in a map are key-value pairs. Maps implement the
Map
interface, which is
unique because the
Map
interface is not a subinterface of
Collection
like the other types of
collections.
Search WWH ::
Custom Search