Java Collections Framework
Java Collections Framework
Collections
Framework
Presented by,
Pronoy Debdas
University Roll Number-21301213059
University Registration Number-132131010060 of 2013
2014
Bca(H)
The Heritage Academy
What Is Collections
Framework?
First introduced with
the Java 2 platform,
Standard Edition,
version 1.2.
A convenient API to
many of the abstract
data types familiar
from computer
science data
structure curriculum
Mathematical
Background
A collection is the same as the
intuitive, mathematical concept
of a set
Historical Collections
Array
Vector
Enumertaion Interface
Dictionary
-Hashtables
-Properties
Interfaces
A special
Collection that
cannot contain
duplicates.
Generalisation
Collection
Set
Map
List
SortedSet
Stores a sequence of elements,
allowing indexing methods
Special Set that retains
ordering of elements.
SortedMap
Special map in
which keys are
ordered
Specialisation
Collection Interface
Works with a
group of
elements in as
general a
manner as
possible.
Supports basic
operations like
adding and
removing.
Set Interface
Extends the
Collection
interface.
Forbids
duplicates
within the
collection.
Set
implementatio
n classes rely
on the
equals()
method of the
object added
to check for
equality.
HashSet
needs to
implement
the
hashCode()
Elements
added to a
TreeSet
must be
sortable
Both
HashSet and
TreeSet
implement
the
Cloneable
interface.
SortedSet Interface
Provides a
special Set
interface for
maintaining
elements in a
sorted order.
The interface
provides
access
methods to
the ends of
the set as well
as to subsets
of the set.
The elements
added to a
SortedSet
must either
implement
Comparable or
you must
provide a
Comparator to
the
constructor of
its
implementatio
n class:
TreeSet.
List Interface
Extends the
Collection
interface to
define an
ordered
collection,
permitting
duplicates.
The interface
adds positionoriented
operations, as
well as the
ability to work
with just a
part of the
list.
The positionoriented
operations
include the
ability to
insert an
element or
Collection, get
an element, as
well as remove
or change an
element.
Map Interface
Not an
extension of
the Collection
interface.
Instead, the
interface
starts off its
own interface
hierarchy for
maintaining
key-value
associations.
The interface
methods can
be broken
down into
three sets of
operations:
altering,
querying, and
providing
alternative
views.
The alteration
operations
allow you to
add and
remove keyvalue pairs
from the map.
Both the key
and value can
be null.
For inserting,
deleting, and
locating
elements in a
Map, the
HashMap
offers the
best
alternative
If you need to
traverse the
keys in a
sorted order,
then TreeMap
is your better
alternative.
HashMap
requires that
the class of
key added
have a welldefined
hashCode()
implementati
on. In
TreeMap,
elements
must be
sortable.
SortedMap Interface
A special Map
interface for
maintaining
keys in a
sorted order.
Working with a
SortedMap is
just like a
SortedSet,
except the
sort is done on
the map keys.
The
implementatio
n class
provided by
the Collections
Framework is
a TreeMap..
List<E>
<<interface>>
Collection<E>
+add(E):boolean
+remove(Object):boolean
+contains(Object):boolean
+size():int
+iterator():Iterator<E>
etc
+add(E):boolean
+remove(Object):boolean
+get(int):E
+indexOf(Object):int
+contains(Object):boolean
+size():int
+iterator():Iterator<E>
etc
<<interface>>
SortedSet<E>
<<interface>>
Set<E>
+add(E):boolean
+remove(Object):boolean
+contains(Object):boolean
+size():int
+iterator():Iterator<E>
etc
+add(E):boolean
+remove(Object):boolean
+contains(Object):boolean
+size():int
+iterator():Iterator<E>
+first():E
+last():E
etc
Conclusion
The Collections Framework provides a well-designed
set of interfaces, implementations, and algorithms for
representing and manipulating groups of elements.
Understanding all the capabilities of this framework
reduces the effort required to design and implement a
comparable set of APIs, as was necessary prior to
their introduction.
Thanks!
Any questions?
References
o) Google.com
o) Bing.com
o) wikipedia.org
o) Collections Framework Support
for o) JDK 1.1
o) java.sun.com