a refference guide of java collection – day4

14
Apex T. G. India Pvt. Ltd Day4 Collection Framework Introduction

Upload: apex-tgi

Post on 25-May-2015

175 views

Category:

Technology


3 download

DESCRIPTION

It is introduced in 1.2 version of java based on key-value paired techniques(Hashing techniques). It represents the three collection view one as a set of key,one as collection of values, or set of key-value mappings. http://www.apextgi.in

TRANSCRIPT

Page 1: A Refference Guide of Java Collection – Day4

Apex T. G. India Pvt. Ltd

Day4

Collection Framework

Introduction

Page 3: A Refference Guide of Java Collection – Day4

1

Map Interface It is introduced in 1.2 version of java.

It is based on key-value paired techniques(Hashing

techniques).

It represents the three collection view one as a set of key,one

as collection of values, or set of key-value mappings. 

Page 4: A Refference Guide of Java Collection – Day4

1

Map Interface We can say that it replace the deprecated abstract class

Dictionary .

A map elements can't contains duplicate keys but can

contain duplicate values.

It is non-synchronized.

Page 5: A Refference Guide of Java Collection – Day4

1

HashMap It is used from 1.2 version of java.

It is based on key-value paired techniques(Hashing

techniques).

It extends AbstractMap class and implements Cloneable and

Serializable interface.

It Doesn't have any fix order for generating result ,even it

does not guarantee that the order will remain constant over

time.

Page 6: A Refference Guide of Java Collection – Day4

1

HashMap It allow null key and value but can have only one null key

and multiple null values.

Iteration cant be performed directly on Map elements.It is

performed by generating collection view of Map.

HashMap class i.e nearly equivalent to Hashtable class by

feature.

Page 7: A Refference Guide of Java Collection – Day4

1

Hashtable It is used from Jdk1.0.

A Hashtable is an array of list.

Each list of array in hashtable known as a bucket.

Bucket position is identified by calling the method

hashcode( ).

A Hashtable contains values based on the key means it is

based on key-value pair.

Page 8: A Refference Guide of Java Collection – Day4

1

Hashtable It implements the Map interface and extends Dictionary

class.

It contains only unique elements.

It doesn’t have any null key or null value.

It is by default synchronized .

An instance of Hashtable has two parameters initial capacity

and load factor that affect its performance.

Page 9: A Refference Guide of Java Collection – Day4

1

Hashtable To successfully store and retrieve objects from a hashtable,

the objects used as keys must implement the hashCode and

equals method.

Simple capacity is the number of buckets in the hash table,

and the initial capacity is simply the capacity at the time the

hash table is created. Note that the hash table is open in

case of a "hash collision", a single bucket stores multiple

entries, which must be searched sequentially.

Page 10: A Refference Guide of Java Collection – Day4

1

Hashtable The load factor is a measure of how full the hashtable is

allowed to get before its capacity is automatically increased.

The initial capacity and load factor parameters are merely

hints to the implementation. The exact details as to when

and whether the rehash method is invoked are

implementation-dependent.

Page 11: A Refference Guide of Java Collection – Day4

1

Hashtable Generally, the default load factor (.75) offers a good tradeoff

between time and space costs. Higher values decrease the

space overhead but increase the time cost to look up an

entry (which is reflected in most Hashtable operations,

including get and put ).

The initial capacity controls a tradeoff between wasted

space and the need for rehash operations, which are time-

consuming.

Page 12: A Refference Guide of Java Collection – Day4

1

Hashtable No rehash operations will ever occur if the initial capacity

is greater than the maximum number of entries the

Hashtable will contain divided by its load factor. However,

setting the initial capacity too high can waste space.

If many entries are to be made into a Hashtable ,creating it

with a sufficiently large capacity may allow the entries to be

inserted more efficiently than letting it perform automatic

rehashing as needed to grow the table.

Page 13: A Refference Guide of Java Collection – Day4

1

HashMap vs Hashtable HashMap is not synchronized where as Hashtable

is synchronized.

HashMap allow null key and null values where as Hashtable

doesn't allow null key as well as null value,it will generate

NullPoniterException when null is added.

Only one thread can take control over this if multiple

threads want to take control over it then they have to

maintain the queue that's why it is known as thread-safe.

Page 14: A Refference Guide of Java Collection – Day4

Thanks

facebook.com/apex.tgi

twitter.com/ApextgiNoida

pinterest.com/apextgi

Stay Connected with us for more chapters on JAVA