11
Apex T. G. India Pvt. Ltd Day3 Collection Framework Introduction

A Refference Guide of Java Collection - Day3

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: A Refference Guide of Java Collection - Day3

Apex T. G. India Pvt. Ltd

Day3

Collection Framework

Introduction

Page 3: A Refference Guide of Java Collection - Day3

1

Set Interface It is introduce in 1.2 version of java.

It doesn't have any fixed type for generating the result .

It doesn't allow duplicacy but if we add duplicate elements

then it doesn't generate any error message it simply avoid

duplicate element.

Page 4: A Refference Guide of Java Collection - Day3

1

Set Interface Some of the set depends on type of element and null.If we

add null or different-different type of elements then it can

generate NullPointerException and ClassCastException.

It doesn't support indexing means doesn't allow to insert

and delete elements at any particular position.

It is heterogeneous by nature but we can make

it homogeneous using generics.

Page 5: A Refference Guide of Java Collection - Day3

1

HashSet It is used since 1.2 version of java.

It doesn't support duplicacy.

It doesn't guarantee any order for generating result even it

does not guarantee that the order will remain constant over

time.

It allow to add null as a element means doesn't generate

NullPointerException when 'null' is added as a elements.

Page 6: A Refference Guide of Java Collection - Day3

1

HashSet It maintain Hashtable class for holding the set elements

internally.

It is not synchronized but we can make it synchronized

according to our requirement.

It is heterogeneous by nature but we can make

it homogeneous using generics.

Page 7: A Refference Guide of Java Collection - Day3

1

TreeSet It is used since 1.2 version of java.

It doesn't support duplicacy.

It generate the order of result as ascending but we can also

generate result in descending order.

It is by-default homogeneous by nature.

Page 8: A Refference Guide of Java Collection - Day3

1

TreeSet When we add heterogeneous type of elements then it

generate ClassCastException at run-time.

It doesn't need any explicit declaration of Comparator as

well as Comparable to perform sorting of elements ,it is

done automatically.

Page 9: A Refference Guide of Java Collection - Day3

1

LinkedHashSet It is used since 1.4 version of java.

It doesn't support duplicacy.

It generate result in insertion order.

It is heterogeneous by nature but we can make

it homogeneous using generics.

It is Hashtable and LinkedList implementation of Set

interface.

Page 10: A Refference Guide of Java Collection - Day3

1

LinkedHashSet It internally use doubly-linked-list for maintaining the

elements of LinkedHashSet.

To use it con-currently for multiple thread, explicitly create

the collection as synchronized using the Collections

class(Collections.synchronizedSet(Set s) ).

Page 11: A Refference Guide of Java Collection - Day3

Thanks

facebook.com/apex.tgi

twitter.com/ApextgiNoida

pinterest.com/apextgi

Stay Connected with us for more chapters on JAVA