Thursday, December 25, 2014

Collection Framework

Collection is a group of individual objects. If we want to represent a group of individual objects as a single entity, then we should go for Collection.

Collection framework defines several classes and interfaces which can be used to represent a group of individual object as a single entity.

Collection and Collection Framework terminology is related to java, but concept is old one which is already there in old languages.

Terminology in Java Equivalent Terminology in C++
Collection Container
Collection Framework STL (Standard Template Library)

9 Key interfaces of Collection Framework

Collection Framework contains both classes and interfaces, as interfaces will provide the much information compare than classes, so we will discuss 9 Key interfaces of Collection Framework.





1. Collection (I) (v1.2):
* Collection is used to represent a group of individual objects as a single entity
* Collection interface defines very common methods which are applicable for any Collection object
* In general, Collection interface is considered as a root interface of Collection Framework
* There is no concrete class which implements Collection interface directly

2. List (I) (v1.2):
* List is used to represent a group of individual objects as a single entity where duplicate objects are allowed and insertion order is preserved
* List is the child interface of Collection interface
* Implementation classes of List interface are,
  1. ArrayList (C) (v1.2)
  2. LinkedList (C) (v1.2)
  3. Vector (C) (v1.0)
  4. Stack (C) (v1.0)
* Here Vector and Stack classes are coming from older version of java, so these classes are called as "Legacy Classes".

3. Set (I) (v1.2):
* Set is used to represent a group of individual objects as a single entity where duplicate objects are not allowed and insertion order is not preserved
* Set is the child interface of Collection interface
* Implementation classes of Set interface are,
  1. HashSet (C) (v1.2)
  2. LinkedHashSet (C) (v1.4)
4. SortedSet (I) (v1.2):
* SortedSet is used to represent a group of individual objects as a single entity where duplicate objects are not allowed and all objects should be inserted in some sorting order
* SortedSet is the child interface of Set interface


5. NavigableSet (I) (v1.6):
* NavigableSet is the child interface of SortedSet interface
* It defines several methods for navigation purpose
* Implementation class of NavigableSet is,
  1. TreeSet (C) (v1.2)
6. Queue (I) (v1.5):
* Queue is used to represent a group of individual objects prior to processing
* Queue is the child interface of Collection interface
* Implementation classes of Queue are,
  1. PriorityQueue (C) (v1.5)
  2. BlockingQueue (C) (v1.5)
  3. LinkedBlockingQueue (C) (v1.5)
  4. PriorityBlockingQueue (C) (v1.5)
7. Map (I) (v1.2):
* Map is used to represent a group of objects as Key-Value pairs
* Duplicate Keys are not allowed
* Duplicate Values are allowed
* Both Key and Value are Objects
* Map is NOT a child interface of Collection
* Generally people are telling Collection is root interface of Collection Framework, but Map is NOT a child of Collection, So if we look at that strictly, we can not tell Collection is the root interface of Collection Framework
* Implementation classes of Map are,
  1. HashMap (C) (v1.2)
  2. LinkedHashMap (C) (v1.4)
  3. WeakHashMap (C) (v1.2)
  4. IdentityHashMap (C) (v1.4)
  5. Hashtable (C) (v1.0)
  6. Properties (C) (v1.0)
* Here Hashtable and Properties classes are coming from older version of java, so these classes are called as "Legacy Classes".

8. SortedMap (I) (v1.2):
* SortedMap is used to represent a group of objects as Key-Value pairs according to some sorting order of keys
* SortedMap is child interface of Map interface

9. NavigableMap (I) (v1.6):
* NavigableMap is child interface of SortedMap interface
* It defines several methods for navigation purpose
* Implementation class of NavigableMap is,
  1. TreeMap (C) (v1.2)

No comments:

Post a Comment