Professional Documents
Culture Documents
Collection Framework
Collection Framework
JAVA
Collection Framework
1
CONTENTS
1. Introduction
2. Method of CF
3. Hierarchy of CF
2
What is Collections ?
It is framework.
set of pre-defined class and interfaces.
It helps programmers to perform different kinds of data structure
operations like – searching, sorting, traversing and processing data
efficiently.
Available in Java.util Package
3
This package contains class and interfaces.
1) Class :-
A class is a user defined blueprint or prototype from which
objects are created.
2) Interfaces :-
Pure abstract class
It has only method declaration and does not have any body.
It is the blueprint of the class.
4
Method Of The Collection Interfaces
add( ) addAll( )
remove( ) removeAll( )
clear ( ) contains ( )
size ( ) containsAll ( )
max ( ) isEmpty ( )
equals ( ) iterator ( )
5
Hierarchy Of Collection Framework
6
Interfaces that extend the Collections Interface
1. Iterable Interface :
Root interface
The Collection interface extends the Iterable interface.
All subclasses of Collection implement the Iterable interface.
It contains only one abstract method. i.e.,
• Iterator<T> iterator()
2. Collection Interface
It extends the iterable interface
This is implemented by all the classes in the collection framework.
7
3. List Interface :
It is child interface of Collection interface.
This interface have all the properties of list data structure.
List interface is implemented by the classes such as,
I. ArrayList
II. LinkedList
III. Vector
Stack.
To instantiate the List interface, we must use :
I. List <data-type> list1= new ArrayList();
II. List <data-type> list2 = new LinkedList();
III. List <data-type> list3 = new Vector();
IV. List <data-type> list4 = new Stack();
8
4. Queue Interfaces :
It also extends the Collection interface.
The class which implements the queue interface are as follow,
I. PriorityQueue,
II. Deque
III. ArrayDeque
Queue interface can be instantiated as:
i. Queue<String> q1 = new PriorityQueue();
ii. Queue<String> q2 = new ArrayDeque();
9
5. Set Interface :
It extends the Collection interface.
It represents the unordered set of elements.
It doesn't allow us to store the duplicate items.
Set is implemented by ,
I. HashSet
II. LinkedHashSet
III. TreeSet
Set can be instantiated as:
I. Set<data-type> s1 = new HashSet<data-type>();
II. Set<data-type> s2 = new LinkedHashSet<data-type>();
III. Set<data-type> s3 = new TreeSet<data-type>();
10
11