Java Collection Framework
Java 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.
Constructors in ArrayList
ArrayList l = new ArrayList();
Here capacity is null/empty
The default initial capacity is ten(10)
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
Vector Class
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
Collections
Collections
is
an
utility
class
available in java.util package for
defining several utility methods for
collection objects.
Collection Hierarchy
Mainly it has been classified into
three categories.
a. List
b. Set
c. Queues