0% found this document useful (0 votes)
21 views

Java Collection Framework

This document discusses Java's collection framework. It provides an overview of common collection interfaces like List, Set, and Queue. It also describes popular implementing classes like ArrayList, LinkedList, and Vector. Key points covered include how collections allow storing multiple objects as a single entity, advantages like dynamic sizing, and performance benefits. Specific methods and behaviors of each interface and class are outlined, such as how ArrayList is best for fast retrieval while LinkedList is more suitable for frequent insertions/deletions.

Uploaded by

Mahesh Mahi
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Java Collection Framework

This document discusses Java's collection framework. It provides an overview of common collection interfaces like List, Set, and Queue. It also describes popular implementing classes like ArrayList, LinkedList, and Vector. Key points covered include how collections allow storing multiple objects as a single entity, advantages like dynamic sizing, and performance benefits. Specific methods and behaviors of each interface and class are outlined, such as how ArrayList is best for fast retrieval while LinkedList is more suitable for frequent insertions/deletions.

Uploaded by

Mahesh Mahi
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

COLLECTION FRAMEWORK

U. Jhashuva1
Asst. Professor,
Dept. of CSE

COLLECTION FRAMEWORK
Collection framework is a class
library to handle group of objects.
It is implemented in java.util
package. It has been including in
java 2.0.
It is collection of classes and
interface.
Each and every class and interface
having its own priority and
advantages.

ADVANTAGES OF
COLLECTIONS
The size must be increase dynamically,
based on our application requirement.
We can overcome the problem of
memory wastage.
We will get the application efficiency
and performance.
The size will be not only increasing but
also decreasing; we can see this nature
in ArrayList in briefly.

Collection
Collection is a root interface for
representing a group of objects
nothing but elements as a single
entity.
It represents group of objects into
single entity.
It is having common methods, which
can be applied on any objects

Methods in collection
List interface :
List is a child interface of Collection.
It is used for group of individual objects as single
entity.
It can allow the duplicate values, null values and
zeros (more than one time).
We can differentiate duplicate values by using
index.
It is having an order of insertion by using index.
It has been included in java 1.2.
We can also call as sequence.

Methods in List interface


ArrayList Class :
It is the child class of List interface.
ArrayList is a increaseable and resizable
array.
It allows the duplicate values.
Heterogeneous (different) objects are
allowed.
Null insertion is possible.
Insertion order is preserved.
It is override the toString() method.

Constructors in ArrayList
ArrayList l = new ArrayList();
Here capacity is null/empty
The default initial capacity is ten(10)

If the ArrayList reaches its initial capacity,


the new ArrayList will be created, with the
(current capacity*3/2)+1.
Example : the minimum capacity is 10.
Then new capacity is (10*3/2)+1 =16.
-cont.,
-Cont.,

Constructors in ArrayList
ArrayList l = new ArrayList(int initial
capacity);
ArrayList l = new ArrayList(collection
c)
Here ArrayList will create with the
equality size of collection object. Used at
inter conversion between collection
objects.

Methods in ArrayList
ArrayList is implements Serializable and
Clonable interfaces.
ArrayList implements the RandomAccess
interface.
Then all the elements in the ArrayList can be
retrieved with same speed.
Thats why ArrayList is best suitable for fast
retrieval.
The drawback of the ArrayList is not suitable for
frequent insertion and deletion operations at
middle of ArrayList.

LinkedList
ArrayList is not suitable for frequent
insertion and deletion at middle of
ArrayList, and then to overcome this
problem we have a new class called
LinkedList.
It is the child class of List interface, Deque,
Queue.
LinkedList class extends
AbstractSequentialList .
Duplicate objects will be allowed.
Cont.,

LinkedList

Null insertion can be allowed.


Insertion order will be preserved.
Heterogeneous object can be allowed.
It is the best suitable for frequent insertion and
deletion operations at middle of the list.
It is also implement the Serializable and
Clonable interfaces.
Up to java1.4 the LinkedList only implements
the List interface, whereas in java1.5 LinkedList
is also implements the Queue interface.

Constructors and Methods in


LinkedList
LinkedList l = new LinkedList();
LinkedList l = new
LinkedList(Collection c);

Vector Class

It is also child class of list interface.


It allows the duplicate values.
It also allows the null values.
The order must be preserved.
It has been available from java1.0
onwards.
Like ArrayList, it is also not suitable
for frequent insertion and deletion
operations in the middle.

Vector Class
It is somewhat similar to ArrayList
but there are some difference
between ArrayList and Vector.
Methods in the ArrayList are not
synchronized, but in Vector methods
are synchronized.

Methods in Vector
Constructors in Vector:
Vector v = new Vector()
Initial capacity is 10

Vector v = new Vector();


The Vector class size will be doubled after
reaches its max capacity.

Vector v = new Vector(int


initial_capacity, int increment_capacity);
Vector v= new Vector (Collection c)

Collections
Collections
is
an
utility
class
available in java.util package for
defining several utility methods for
collection objects.

TYPES OF COLLECTION FRAMEWORK


Based on the way of strong the
objects, the collection framework is
categorized into two approaches.
(a) Collection hierarchy.
(b) Map hierarchy

Collection Hierarchy
Mainly it has been classified into
three categories.
a. List
b. Set
c. Queues

You might also like