0% found this document useful (0 votes)
5 views

Collection Final Grooming

Notes

Uploaded by

dhaneshsuyambu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Collection Final Grooming

Notes

Uploaded by

dhaneshsuyambu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Collection Framwork

Sunday, May 14, 2023 9:55 AM

 What is Collection?
○ It Represent Collection of Objects
 What is FrameWork or Collection FrameWork?
○ It is a ready made architecture to perform Crud operation on Collection by using Built-in
Methods.
 What is Collection Hirarachy?
○ It is the combination of built in classes and interface with predefined Methods to perform
Crud operation on Collection

 Characteristic of Following collections

 ArrayList

 It is one of the implementation class of List Interface.


 Present Since JDK 1.2.
 It internally stores the data in the form of Array of type Object.
 Initial capacity of ArrayList is 10.
 Incremental capacity is current capacity x 3 /2+1
 ArrayList implements a data structure called growable array / resizable array.
 ArrayList implements marker interfaces like
○ Clonable
○ Serializable
○ RandomAcces
 Duplicates are Allowed
 Order of Insertion is Maintained
 Null insertion is allowed
 Indexing is aplicable

Situations to use ArrayList :


 ArrayList is good for data retrieval & search operation . Because time taken to search any data
in entire List is same.

Situations not to use ArrayList :


 It we try to add the data in between the list then all the existing data gets shifted to next
position , so because of this shift operation the performance becomes slow
****************************************************************************************
 LinkedList
 LinkedList is one of the implementation class of List Interface.
 Presence Since JDK 1.2
 LinkedList stores the data in the form of Nodes. Where in every node is connected to next and
its previous node.
 The first node does not have previous node information and last node does not have next node
information.
 The internal data structure is Doubly LinkedList.
 LinkedList implements marker interface like Serializable , Clonable but not RandomAccess.

 Duplicates are allowed.


 Insertion order is preserved.
 Null insertion possible.
 Good for modification / addition / removal.
 No initial capacity / no incremental capacity.

Situations to use LinkedList :


 LinkedList doesnÕt have any shift operation , hence it is suitable for insertion or removal of data
in between.

Situations not to use List :


 LinkedList is not suitable for any search / retrieval operation
****************************************************************************************
 HashSet
 HashSet is one of the implementation class of Set interface.
 Present SinceJDK 1.2.
 HahSet implements data Structure called HashTable.
 Initial capacity is 16.
 Fill ratio or load factor is 75%.

 HashSet doesnÕt allow duplicate data.


 Insertion order is not preserved.
 Objects are inserted based on hash code.
 Heterogeneous Obj is allowed.
 Accepts Single null element.
 Implements Clonable , Serializable marker interface.
 Search Operation Works Based on HashCode

****************************************************************************************
 TreeSet

 TreeSet is one of the implementation class of Set interface.


 Present since JDK 1.2.
 TreeSet is mainly used for uniqueness and sorting. i.e.., TreeSet doesnÕt store duplicate data
 Default natural sorting order: Ascending order… • Number 0 – 9 • Alphabet a – z & A – Z
 TreeSet is not a hash based collection , the data structure used is Balanced tree.
 TreeSet is Homogeneous i.e.., TreeSet can store only one type of data.
 ➢ TreeSet cannot store even single null element.
 TreeSet either uses Comparable or Comparator interface.
***************************************************************************************

Map

 What is Map?
○ It is a Datastr Where we store the Data in key-value Pair
○ Map Hierrarchy

 HashMap

 HashMap is a map based collection which is used to store entries , and it is a implementation
class of Map interface.
 Present since JDK 1.2.
 HashMap is hash based , Hence the internal data structure is HashTable.
 Initial capacity of HashMap is 16.
 Fill ratio or load factor is 75%
 HashMap can store single null key.
 HashMap can store heterogeneous data and does not maintain any insertion order.
****************************************************************************************
 TreeMap

 It is one of the implementation class of Map interface.


 Present since JDK 1.2.
 TreeMap is used mainly for sorting data based on key.
 TreeMap implements default natural sorting order on the key using Comparable interface.
 For custom sorting we use Comparator.
 It cannot store even a single null key.
 TreeMap is homogeneous.
 NullPointerException , when we try to add null.
****************************************************************************************
 LinkedHasMap

 LinkedHashMap is a map based collection which is used to store entries , and it is a


implementation class of Map interface.
 Present since JDK 1.4.
 LinkedHashMap is hash based , Hence the internal data structure is HashTable.
 Initial capacity of LinkedHashMap is 16.
 Fill ratio or load factor is 75%
 LinkedHashMap maintains insertion order.
 LinkedHashMap can store single null key.
 LinkedHashMap can store heterogeneous data and does not maintain any insertion order.

****************************************************************************************
 HashTable
 Hashtable is one of the implementation class of Map interface.
 Present since JDK 1.0 [legacy class].
 It is also a hash based collection , hence data structure used is HashTable.
 Hashtable is Single threaded. i.e.., methods are synchronized.
 Initial capacity is 11.
 Load factor or fill ratio is 75%.
 Hashtable cannot store even a single null key.
 Hashtable is slower than HashMap. Because it is Single threaded.
 There are 4 overloaded constructor present in Hashtable
****************************************************************************************

You might also like