a refference guide of java collection - day2

19
Apex T. G. India Pvt. Ltd Day2 Collection Framework Introduction

Upload: apex-tgi

Post on 23-Jan-2015

109 views

Category:

Documents


4 download

DESCRIPTION

 

TRANSCRIPT

Page 1: A Refference Guide of Java Collection - Day2

Apex T. G. India Pvt. Ltd

Day2

Collection Framework

Introduction

Page 2: A Refference Guide of Java Collection - Day2

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

1

Classes & Interfaces Set

List

Quque

Properties

ArrayList

LinkedList

Vector

 

Page 4: A Refference Guide of Java Collection - Day2

1

Classes & Interfaces Stack

HashSet

TreeSet

LinkedHashSet

ArrayDeque

Iterator ListIterator Enumeration

 

Page 5: A Refference Guide of Java Collection - Day2

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

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 8: A Refference Guide of Java Collection - Day2

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

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

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

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

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

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

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

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

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

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

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

Thanks

facebook.com/apex.tgi

twitter.com/ApextgiNoida

pinterest.com/apextgi

Stay Connected with us for more chapters on JAVA