Pages

Some Basic point about Map, Set and List from JAVA Collection

A Set is a Collection that cannot contain duplicate elements

three general-purpose Set implementations:

1. HashSet :

    Uses HashTable to store its element.
    Uses Hash Function for Storing and retrieving its element.
    Order is not maintain in HashSet.

2. TreeSet :

   Uses Red-Black tree to store its element.
   Order of elements maintained according to their values.

3. LinkedHashSet (LinkeList + HashSet)

     Implemented as a hash table with a linked list running through it.
     orders its elements based on the order in which they were inserted into the set (insertion-order)


A List is an ordered Collection (sometimes called a sequence). Lists may contain duplicate elements

The Java platform contains two general-purpose List implementations

1. ArrayList :
  
     Use variable-size array to store element
     element can access randomly using index.
     maintain the elements insertion order

2. LinkedList :

   Doubly-linked list implementation of the List
   Sequential access of elements
   maintain the elements insertion order

Note : LinkedList element deletion is faster compared to ArrayList.


A Map is an object that maps keys to values.
A map cannot contain duplicate keys: Each key can map to at most one value

Java platform contains three general-purpose Map implementations:

1.HashMap :

   Hash table based implementation of the Map interface
   makes no guarantees as to the order of the map; in particular, it does not           guarantee that the order will remain constant over time.


2.TreeMap :
 
   A Red-Black tree based NavigableMap implementation
   The map is sorted according to the natural ordering of its keys


3.LinkedHashMap :
 
   Hash table and linked list implementation of the Map interface
   maintain the insertion order