a refference guide of java collection - day2
DESCRIPTION
TRANSCRIPT
1
Iterable Interface:
public interface java.lang.Iterable<T extends java.lang.Object>
extends java.lang.Object
{
public abstract java.util.Iterator<T> iterator();
}
Due this iterator method, collection elements allow iteration .
<T extends java.lang.Object> is used as Generics notification.
1
Classes & Interfaces Set
List
Quque
Properties
ArrayList
LinkedList
Vector
1
Classes & Interfaces Stack
HashSet
TreeSet
LinkedHashSet
ArrayDeque
Iterator ListIterator Enumeration
1
List Interface Generate result into insertion order.
Support duplicacy means it allow to add duplicate elements.
Support indexing means can insert element at any particular
position.
Internally maintain dynamic array and linkedlist for holding
the elements.
1
List Interface It can be synchronized and non-synchronized both.
all list sub-classes permits null as a elements.
It is heterogeneous by nature but we can make
it homogeneous using generics.
To perform sorting on list we can use Collections class and
its method.
1
List Interface
1
ArrayList It used since 1.2 version of java.
Generate result into insertion order.
Support duplicacy means it allow to add duplicate elements.
Support indexing means can insert element at any particular
position.
Internally maintain dynamic array for holding the elements.
It is heterogeneous by nature but we can make
it homogeneous using generics.
1
ArrayList It is by default non-synchronized but we can make it
synchronized using resource class 'Collections'.
Manipulation is slow as compared to other list because it
can shift the element in only one direction.
As elements are added to an ArrayList,its capacity grows
automatically. The details of the growth policy are not
specified .
1
Vector It is used since the first version of java(jdk1.0).
Generate result into insertion order.
It support duplicacy.
Increase the size just double of initial capacity.
It is known as legacy class(old class) .
1
Vector it is by-default synchronized or thread-safe.
Because of synchronization it slow down processing ,so not
used very frequently.
Internally maintain dynamic array for holding the elements.
It is heterogeneous by nature but we can make
it homogeneous using generics.
1
LinkedList It is used since 1.2 version of java.
Generate result into insertion order.
Support duplicacy means it allow to add duplicate elements.
Support indexing means can insert element at any particular
position.
1
LinkedList It is by default non-synchronized but we can make it
synchronized using resource class 'Collections'.
Manipulation is fast as compared to other list because it
need not shifting it can shift either one node forward or
backward.
1
LinkedList Have more method for manipulation on collections element
compare to other list.
It is heterogeneous by nature but we can make
it homogeneous using generics.
Internally maintain doubly-linkedlist node for holding the
elements.
1
Difference b/w List Classes ArrayList and Vector both having same data structure
internally, which is Array
Vector is by default synchronized, means at a time only one
thread can access its methods from out side, where as
ArrayList is non-synchronized means any number of threads
can access at a time
1
Difference b/w List Classes But we can make ArrayList as synchronized by using
Collections class.
Both Vector and ArrayList have capability to re-size
dynamically, but Vector will Doubles the size of its
array(initial size) when its size increased, but ArrayList
increased by Half only .
1
Difference b/w List Classes ArrayList shows better performance as compare to
Vector, except Synchronization both are almost same in
their performance.
Vector is Synchronized means thread safe, means at one
time only one thread can access so its processing very slow
compared to ArrayList, because of that used rarely in real
time projects.
1
Difference b/w List Classes we should not require synchronized methods always.So
always try to use ArrayList rather Vector if project does not
required any Synchronization.
Thanks
facebook.com/apex.tgi
twitter.com/ApextgiNoida
pinterest.com/apextgi
Stay Connected with us for more chapters on JAVA