Tuesday, October 18, 2016

Collection in java - Basics

Hello guys , today after almost 1-2 months , I am back with bang ;) , yeah so today i am gonna share my notes about the collection -basics

--------------------------------------------------------------------------------------------------------------------------
Collection
Collection interface
In Array we should know the size at design time
Limation of Array
-Fixed in size
-Homogeneous elements
- No underlying Datastructure

Need of collections
-----------------------
An array is an indexed collectiton of fixed num of homogeneous data elements
-Collections are growable in nature
-Collections can hold both the homogeneous & hetrogeneous Objects
-Implemented with some standard Data structure
-

Diff btw array & collections
-array are fixed in size | collection are growable naturally
-wrt memory arrays are not recommended to use | wrt to memory collections are recommended to use
-wrt performance arrays are recommended to use | collection are not recommended to use
-there is no underlying data structure for arrays and hence ready made method support is not available | every collection class is implemented based on some standard data structure
-array can hold both primitive and objects | collection can only hold objects

What is collection & what is collection framework ?
-Collection is a group of individual objects as a single entity

What is collection framework?
-collection framework defined several class and interfaces .
In Collection framework , there are 9 key interface
1) Collection(I) - 
-It defines the most common methods which are applicable fro an collection object
-In general collection interface is considered as root interface of collection framework.
Note  - There is no conecrete class which implements collection interface directly.

Difference btw collection and collections ?
Collection - interface
Collectitons - Class - its a utility class which define utlitly methods which sorting , seaching.
2) List(T) -(1.2v)

List interface is a child interface of Collection Interface
If we want to represent a group of individual objects as a single entity where duplicates are allowed and insertion order preserved then we use List.
Concrete class of List (I)
-ArrayList(1.2v)
-LinkedList(1.2v)
-Vector(1.0v)
-Stack(1.0v)
Note Vector and stack are legecy classes

3) Set (T) 
Set is a child interface of collection interface
If we want to represent a group of individual objects as a single entity where duplicates are not allowed and insertion order not preserved then we use Set(I)

Concrete class of Set (I)
-HashSet(1.2v)
-LinkedHashSet (1.4v)

** Difference between List and set
Duplicates are allowed | Duplicate are not allowed
Insertion Order preserved | insertion order not preserved

4) SortedSet(I) (1.2v)
interface SortedSet implements Set
SortedSet is a child interface of set
if we want to represent a group of individual objects as a single entity where duplicates are not allowed but all the objects should be inserted according to some sorting order then we use SortedSet

5) NavigableSet(I) (1.6v)
navigable set is a child interface of sortedset
It define several methods for navigation purpose.

6) Queue(I) (1.5v)
it is child interface of collection
if we want to represent a group of individual objects pior to processing then we should go for queue.
ex -before sending a mail all mail ids we have to store somewhere and in which order we saved in the same order mails should be delilvered First in first out for this requirement queue concesp is best choice.
ConcreteC classes
-Prioirity Queue(1.5v)
-Blocking Queue(1.5v)
-LinkedBlockingQueue
-PriorityBlockingqueue
** All the above interface  meant to represent a group of individual objects
** if we want to represent a group of objects as key value pair then we should go for map interface

7) Map(I)(1.2v)

Map is not the child interface of collection
if we want to represent a group of indicula object as key value pair then we use map
Concrete classes
-HashMap -> LinkedHashMap
-WeakHashMap
IndentityHashMap
-Dictonary
-Hashtable
-Properties
8) Sorted Map(I)(1.2v)
it is child interface of map
if we want to represnt a group of key value pairs according to some sorting order of keys then we should go for sortesMai

9) Navigable Map(I)(1.6v)
it is a child interface of SortedMap
define several method of navigable purpose

Concrete Class
-TreeMap (1.2v)

In next post , i will share about the in depth knowledge of ArrayList class.
Hope this post will help you in understanding the basics of Collection interface.

Thanks for Reading
-Noeik

0 comments:

Post a Comment