Java Collections framework

Java Collections is a framework in java, which help to hold a group of objects together. A group of Objects that belongs to the same type or a different set of types. A framework is nothing but a certain classes and interfaces(interfaces may contain or may not contain) helpful to provide a solution to the common or repeated problems.

Java Collections framework not only group the Objects and provides the flexibility to manipulate all the objects in the group or any object among the group. This manipulation and processing can be done by the Programmer choice via wide API's of the Collection Framework.

Before introducing or adding the Java Collections framework, in Java there were few classes which helps to group the object and can perform up to certain actions but were not that much flexible to use because of no common interface among these or no common API's.

Java Collection framework consists of three types of collection interfaces, all these interfaces extends the Collection interface we may say Collection interface is root for following interfaces.

List Interface

List is an interface, whose concrete implementations are ArrayList, LinkedList and Vector. We have covered about these classes in later chapters.

Behavior of the List

Set Interface

Set is an interface in the Java Collection framework, like the List interface this Set interface also extends the Collection interface. Set interface is implemented the following concrete classes.

We have covered the Concrete classes of Set interface in the later chapters. The following is the behavior of the Set interface or in other words the classes which are implementing the Set interface should possess the following behavior.

Behavior of the Set

Queue Interface

Queue is the interface in the Collection Framework, like Set and List interfaces Queue also extends the Collection interface. There are no direct classes which are implemented the Queue interface but there are classes implemented the child interfaces of the Queue interface.

Behavior of Queue

Map Interface

Map is the only interface in the Java Collection Framework which will not extend the Collection interface. Map holds the Objects or elements in the key value pair. While fetching or processing the objects done by via key of that respective object stored or grouped in the Map.

Map mapObject = new HashMap();

mapObject.put(1, "Value 1");

mapObject.put(2, "Value 2");

If we see above lines of code where 1 and 2 will be the Keys, "Value 1" and "Value 2" will be the values of Key 1 and 2 respectively.

Behavior of the Map