Professional Documents
Culture Documents
Java Collections
Framework
Agenda
Collection Categories
Collection Operations
The JFC Collection Hierarchy
Collection
Categories
What is a collection?
A collection is a group of elements that can
be treated as a single entity
Types
Homogeneous
Requires that all of its elements be of the same
type
Heterogeneous
Allows the elements to be of different types
Some collections allow the element type to
be a primitive type or an object, while some
are more restrictive
Some collections allow duplicate elements
and others do not
Some collections allow NULL elements and
others do not
Collection Categories
Collections can be categorized by how the
elements they contain are organized
Linear
Hierarchical
Graph
Nonpositional
Collection Category - Linear
Elements are arranged in sequence such
that all elements except the first have a
unique predecessor and all except the last
have a unique successor
There are two ends to every linear
collection
Linear collection may or may not allow null
or duplicate entries
Collection Category – Linear
Examples
List
maintains a notion of position
access (insertions, deletions, and retrievals) can be done at any
position in a list
also known as a sequence
Stack
all access are restricted to one end (top)
trays stacked in a cafeteria
Back button of a browser makes use of a stack
Queue
all insertion in which all insertions are done at one end (rear)
all deletion are done at the other end (front)
People waiting to use an ATM machine
Collection Category - Hierarchical
Trees
Elements of a tree are called nodes
A nonempty tree has a special node
called root, which has no predecessors
(called parents) and zero or more
successors (called children)
Elements called leaves have one
parent and no children.
All other elements reside in the interior
of the tree and have one parent and
one or more children
It cannot contain cycle
Collection Category – Hierarchical
Examples
Tree
general hierarchical collection that does not specify how
many children an element may have
Binary Tree
a binary tree is one in which a node can have no more
than two children
Binary Search Tree
a binary search tree is a binary tree that orders its
elements to facilitate searching
Collection Category - Graph
Allows cycles
An element can have zero or more
predecessors and zero or more
successors.
The elements of a graph are called
vertices and the connection between
them are edges.
Example
Computer network topology
May or may not allow duplicate entries
Undirected Graph
Two elements that are connected by
an edge are both successor and
predecessor to one another
Directed Graph
The edges clearly specify which mode
is the predecessor and which the
successor
Collection Category – Nonpositional