The interface provides information class just act like dummy things – implementation of details.

The Collection interface (java.util.Collection) and Map interface (java.util.Map) are two main root interfaces of Java collection classes.

There was no concept of collection framework before jdk 1.2

Hierarchy of Collection Framework

First of all, learn about collection Interfaces.

Java collection

 

1. Collection

collection interface defines the most common methods which are applicable to any collection objects. In general, collection framework is considered as root interface of collection framework.

There is no concrete class which implements as root interface of collection framework.

Difference between collection and collections

The collection is an interface which can be used to represent a group of individual objects as a single entity. Whereas, collections is a utility class present in java.util package to define several utility methods for collection objects.

2. List

 list is child interface of the collection.

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

list in java collection

 

vector and stack were introduced in JDK 1.0 so they are also called legacy classes. But, Both were re-engineered in JDK 1.2 to implement list interface.

3. SET

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

set in java collection

Difference between List and set

difference between set and list

 

4. SortedSet

It is the child interface of the 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 the sorted set.

5. Navigation set

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

It was introduced in jdk 1.6

6. Queue

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

Queue concept was introduced in jdk 1.5

All the above interfaces – collection, list, set, sorted set, Navigation set and queue, all were meant for representing a group of individual objects. But, if we want to represent a group of objects as key-value pairs then we should go for map interface.

Now let’s have a look at Map

 

map in java collection

7. Map

The map is not the child interface of the collection.

If we want to represent a group of individual objects as key-value pairs then we should go for Map.

First of all, learn about key-value pairs.

key value pair

Here, RollNO is Key and Name is Value. If we want to access “Ravi” then we will call key – 101 and so on.

Both key and value are objects. Duplicates keys are not allowed but the value can be duplicated.

 

8. SortedMap

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

9. NavigableMap

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

It was introduced in jdk 1.6

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here