a refference guide of java collection - day2
DESCRIPTION
TRANSCRIPT
![Page 2: A Refference Guide of Java Collection - Day2](https://reader036.vdocument.in/reader036/viewer/2022062511/54c1b8f74a79592f6a8b45a9/html5/thumbnails/2.jpg)
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.
![Page 3: A Refference Guide of Java Collection - Day2](https://reader036.vdocument.in/reader036/viewer/2022062511/54c1b8f74a79592f6a8b45a9/html5/thumbnails/3.jpg)
1
Classes & Interfaces Set
List
Quque
Properties
ArrayList
LinkedList
Vector
![Page 4: A Refference Guide of Java Collection - Day2](https://reader036.vdocument.in/reader036/viewer/2022062511/54c1b8f74a79592f6a8b45a9/html5/thumbnails/4.jpg)
1
Classes & Interfaces Stack
HashSet
TreeSet
LinkedHashSet
ArrayDeque
Iterator ListIterator Enumeration
![Page 5: A Refference Guide of Java Collection - Day2](https://reader036.vdocument.in/reader036/viewer/2022062511/54c1b8f74a79592f6a8b45a9/html5/thumbnails/5.jpg)
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.
![Page 6: A Refference Guide of Java Collection - Day2](https://reader036.vdocument.in/reader036/viewer/2022062511/54c1b8f74a79592f6a8b45a9/html5/thumbnails/6.jpg)
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.
![Page 7: A Refference Guide of Java Collection - Day2](https://reader036.vdocument.in/reader036/viewer/2022062511/54c1b8f74a79592f6a8b45a9/html5/thumbnails/7.jpg)
1
List Interface
![Page 8: A Refference Guide of Java Collection - Day2](https://reader036.vdocument.in/reader036/viewer/2022062511/54c1b8f74a79592f6a8b45a9/html5/thumbnails/8.jpg)
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.
![Page 9: A Refference Guide of Java Collection - Day2](https://reader036.vdocument.in/reader036/viewer/2022062511/54c1b8f74a79592f6a8b45a9/html5/thumbnails/9.jpg)
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 .
![Page 10: A Refference Guide of Java Collection - Day2](https://reader036.vdocument.in/reader036/viewer/2022062511/54c1b8f74a79592f6a8b45a9/html5/thumbnails/10.jpg)
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) .
![Page 11: A Refference Guide of Java Collection - Day2](https://reader036.vdocument.in/reader036/viewer/2022062511/54c1b8f74a79592f6a8b45a9/html5/thumbnails/11.jpg)
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.
![Page 12: A Refference Guide of Java Collection - Day2](https://reader036.vdocument.in/reader036/viewer/2022062511/54c1b8f74a79592f6a8b45a9/html5/thumbnails/12.jpg)
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.
![Page 13: A Refference Guide of Java Collection - Day2](https://reader036.vdocument.in/reader036/viewer/2022062511/54c1b8f74a79592f6a8b45a9/html5/thumbnails/13.jpg)
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.
![Page 14: A Refference Guide of Java Collection - Day2](https://reader036.vdocument.in/reader036/viewer/2022062511/54c1b8f74a79592f6a8b45a9/html5/thumbnails/14.jpg)
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.
![Page 15: A Refference Guide of Java Collection - Day2](https://reader036.vdocument.in/reader036/viewer/2022062511/54c1b8f74a79592f6a8b45a9/html5/thumbnails/15.jpg)
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
![Page 16: A Refference Guide of Java Collection - Day2](https://reader036.vdocument.in/reader036/viewer/2022062511/54c1b8f74a79592f6a8b45a9/html5/thumbnails/16.jpg)
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 .
![Page 17: A Refference Guide of Java Collection - Day2](https://reader036.vdocument.in/reader036/viewer/2022062511/54c1b8f74a79592f6a8b45a9/html5/thumbnails/17.jpg)
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.
![Page 18: A Refference Guide of Java Collection - Day2](https://reader036.vdocument.in/reader036/viewer/2022062511/54c1b8f74a79592f6a8b45a9/html5/thumbnails/18.jpg)
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.
![Page 19: A Refference Guide of Java Collection - Day2](https://reader036.vdocument.in/reader036/viewer/2022062511/54c1b8f74a79592f6a8b45a9/html5/thumbnails/19.jpg)
Thanks
facebook.com/apex.tgi
twitter.com/ApextgiNoida
pinterest.com/apextgi
Stay Connected with us for more chapters on JAVA