Collection Framework

Collection Framework

  • Collection framework define set of classes and interface which used
    to hold hold any type of object.
  • Collection framework library is used to store,manage, manipulate and remove object in a particular structure.

Collection

  • Collection interface is root interface in collection framework.which
    defines the properties of collection type.
  •  Collection is a group of object which is used to store and process object in structured manner.

Types of collection.
1. List

  •  Arraylist
  •  Vector
  • Linkedlist

2. Queue

  • LinkedList
  •  PriorityQueue

3. Set

  • Hashset(random)
  • Linked hashset(preserve order)
  • Treeset(ascending order)

 

 

List

  • List is type of collection which is used to store any type of object.
  •  It stores the object sequentially.
  • All the object store in the list will have index.
  • List preserve insertion order.
  • List allow to insert duplicate object as well as null element.
  • List element can be proccesed based on index.

There are a three type of list.

  1.  Arraylist
  2. Vector list
  3.  Linked list

Arraylist

  • Arraylist is a implementation class of list interface.
  •  Arraylist implemenet marker interface

— Serialize
— Cloneable
— Random access

  • Arraylist built on re-sizable array data structure.
  • Arralist size grows with a below formula.

new capacity=(old capacity 3/2)+1

  • Array list class has 3 overload constructor.
    1. no arg constructor
    2. int arg constructor
    3. collection type arg constructor.
  • In Arraylist accessing and retrieval of element is faster compared to linkedlist.
Vector

  • Vector is implementation class of list interface
  • Vector implements three marker interface
    — Serializable
    — Clonable
    — Random access
  • Vector is a legacy class which is introduced in java 1.0
  •  All method in vector is synchronized so it is thread safe class.
  • Whenever we want to achieve thread safety we go through vector.
  •  Vector size grows by doubling the capacity.
Linkedlist

  • Linked list is a implementation class of list and queue interface.
  • Linked list also implement queue ,hence it follow FIFO.
  • Linkedlist implement only two marker interface.
    —  Serializable
    —  Clonable
  •  Linkedlist built on doubly Linkedlist data structure.
  • Linkedlist preferable whenever frequent operation is insertion or deletion
  •  Linkedlist grows one element at a time.

 

Queue

  • Queue is a type of collection which is used store the object in fifo order.
  •  The object are store randomly without index.
  •  Queue allows duplicate object insertion.
  •  Null insertion is not allowed.
  •  Queue element can be accessed by using polling mechanism.
  •  There are a two types of queue.
    1. Linkedlist
    2. Priority queue.
  • Linkedlist

    •  Linked list is a implementation class of list and queue interface.
    •  Linked list also implement queue ,hence it follow FIFO.
    • Linkedlist implement only two marker interface.

    1. Serializable
    2. Clonable

    • Linkedlist built on doubly linkedlist data structure.
    • Linkedlist preferable whenever frequent operation is insertion or deletion
    • Linkedlist grows one element at a time.

    Priority Queue

    •  Priority queue is an implementation class of queue interface.
    • It stores objects in ascending order based on some priority.
    • It store only homogeneous element which are of comparable type.
    • Constructor of priority queue

    — Zero parameter
    priorityqueue()

    — Comparator object type
    priorityqueue(comparator c1)

     

    Set

    • Set is type of collection which is used to store unique object.
    • Set does not allow to store duplicate object.
    •  Null insertion is allowed.
    •  The object are store randomly without any index.
    • Set element can be retrieve by using for each loop or iterator.

    There are three type of set

    1.  Hashset
    2. Linkedhashset
    3. Treeset

    Hashset

    • Hashset is a type of set which implement set interface
    • It implement two marker interface

    1. Serializable
    2. Clonable

    • Hashset is implemented using hash table data structure.
    • Hash set does not allow duplicate object. Hash set inserts object based on the hash code,
    •  Does not preserve insertion order.
    • Null insertion is allowed.
    • Hash set is preferable whenever frequent operation is searching, since the object searching based on hash code.

    Constructor are overloaded IN Hash set

    — Hashset
    — Hashset(initial capacity)
    — Hashset(collection c1)
    — Hashset(int initialcapacity,float loadfactor)

    Linkedhashset

    •  Linkedhashset is class which sub class of hashset.
    •  Linkedhashset is implemented based on hybrid data structure(hashing+linkedlist)
    •  Linkedhashset preserve insertion order
    • Duplicate object are not allowed, null insertion is allowed.
    Treeset

     

    •  Treeset is a type of set which implement navigable set,which is sub
      interface of sortset
    • Treeset is implemented based on balanced tree data structure.
    • Treeset does not allow duplicate object.but null insertion is allowed.
    • Does not preserve insertion order,object inserted according to sorting order
    • Treeset allow only comparable type object.
    • By default object are sorted in ascending order.

    Treeset overload constructor

    — Treeset(comparator c1)
    — Treeset(sortedset c1)
    — Treeset(collection c1)

    Leave a Reply