9 key interfaces of collection framework:

 1. Collection Interface :

  • If we want to represent a group of individual objects as a single entity then we should go for collection.
  • Collection interface defines the most common methods which are applicable for any collection object.

For ex:-

Add Object

Remove Object

Contains()

  • In general collection interface is considered as root interface of collection framework.

collection framework

NOTE:-THERE IS NO CONCRETE CLASS WHICH IMPLEMENTS COLLECTION INTERFACE DIRECTLY.

Difference between collection and collections

Collection

Collections

Collection is an interface which can be used to represent a group of individual objects as a single entity.

Collections is an utility class present in java.util.package to define several utility method (Like sorting searching) for collection objects.

2. List Interface :

  • List is the child interface of collection.
  • If we want to represent a group of individual objects as a single entity where duplicates are allowed and insertion order preserved then we should go for list.

java list collection

  • Legacy classes (vector and stack) :- Classes coming from older version/generation are called as legacy classes.

3. Set Interface :

  • It is the child interface of collection.
  • 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 should go for set.

java set interface collection frameworkDifference between list and set

LIST SET
1.Duplicates are allowed 1.Duplicates are not allowed
2.Insertion order preserved 2.Insertion order not presetved

4. Sorted Set Interface :

  •  It is the 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 objects should be inserted according to some sorting order then we should go for sorted set.

java sorted set collection

5. Navigable Set Interface :

It is the child interface of sorted set it defines several methods for navigation purpose.

java navigable set collection

6. Queue Interface :

  • It is the child interface of collection.
  • If we want to represent a group of individual objects prior to processing then we should go for queue.

java queue collection

For Ex :- Before sending a mail all mail id’s we have to store somewhere and in which order we saved in the same order mails should be delivered(first in first out) for this requirement queue concept is the best choice.

Note:-All the above interfaces (Collection,List,Set,SortedSet,NavigableSet and Queue) meant for representing group of individual objects.

If we want to represent a group of objects as key value pairs then we should go for map interface.

7. Map Interface :

  •  Map is not the child interface of collection.
  •  If we want to represent group of individual objects as key value pairs then we should go for Map.

java map interface

For Ex:- We have data (below). Both key and values are objects, duplicate keys are not allowed but values can be duplicate.

ROLL NO

NAME

101

Neeraj

102

Preeti

103

Shephali

8. Sorted Map Interface :

  •  It is the child interface of Map.
  •  If we want to represent a group of key value pairs according to some sorting order then we should go for sortedMap.

java sortedmap collection

9. Navigable Map Interface :

  •  It is the child interface of Sorted Map.
  •  It defines several utility methods for navigation purpose.

java Navigablemap collection
SORTING

  1. Comparable(I):- Default native sorting order.
  2. Comparator(I):-If we want to implement customize sorting.

CURSORS

IF YOU WANT ONE BE ONE OBJECTS FROM COLLECTIONS

  1. Enumeration(I)
  2. Iterator(I)
  3. ListIterator(I)

COLLECTION INTERFACE DETAILS

  • If we want to represent a group of individual objects as a single entity then we should go for collection.
  • In general collection interface is considered as root interface of collection framework.
  • Collection interface defines the most common methods which are applicable for any collection objects.

Important methods of collection interface

  • boolean add(Object o)
  • Boolean addAll(Collection c)
  • boolean remove(Object o)
  • boolean removeAll(Collection c)
  • boolean retainAll(Collection c)
  • void clear()
  • boolean contains(Object o)
  • boolean containsAll(Collection c)
  • boolean isEmpty()
  • int size()
  • Object[] to Array()
  • Iterator iterator()

NOTE:- 1) Collection interface doesn’t contain any method to retrieve objects there is no concrete class which implements collection class directly.

2) No get methods.

 

Leave a Reply