Collection Framework in Java

Collection Framework in Java provides a powerful and efficient way to manage and manipulate collections of objects, making it an essential tool for Java Developers.

It contains several clauses and interfaces that can be used to represent a group of individual objects as a single entity.

Collection Framework in Java

Key Interfaces of Collection Framework

  • Collection
  • List
  • Set
  • SortedList
  • NavigableSet
  • Queue
  • Map
  • SortedMap
  • NavigableMap

Collection

  • If we want to represent a group of individual Objects as a single entity then we should go for the Collection
  • Collection interface defines the most common methods, applicable on Collection objects
  • Collection interface is considered as root interface of Collection Framework
  • There is no concrete class, which implements collection interface directly

Difference between Collection and Collections

The collection is an Interface. If we want to represent a group of individual Objects as a single entity then we should go for the Collection

Collections is a Utility Class, available in Java. util package. Collections Class defines several utility methods for Collection Objects (like sorting, searching, etc)

List

This Interface is the Child of the Collection Interface i.e., the List interface extends the Collection interface. If we have to represent more than one object as a single entity, where duplicates are allowed and insertion order must be preserved then we should use List.

Set

This Interface is the Child of the Collection Interface i.e., the Set interface extends the Collection interface. If we have to represent more than one object as a single entity, where duplicates are not allowed and insertion order is not required to be preserved then we should use Set.

SortedSet

This Interface is the Child of the Set Interface i.e., the SortedSet interface extends the Set interface. If we have to represent more than one object as a single entity, where duplicates are allowed and all object insertion is performed according to some sorting order then we should use SortedSet.

NavigableSet

This interface is a child of SortedSet i.e., the NavigableSet interface extends SortedSet. NavigableSet contains several methods for navigation purposes such as finding the closest element to the given value.

Queue

It is the child Interface of Collection and represents a collection used to hold elements before processing Queue generally follows a First in First Out (FIFO) order but according to our requirements, we can implement our priority order.

All the above interfaces are meant to represent a group of objects. If you want to represent a group of objects as a key-value pair then we should go for Map.

Map

The Map Interface defines a method to store, retrieve, and manipulate data using keys. Both key and value are object only where duplicate keys are not allowed but duplicate values are allowed.

SortedMap

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. In SortedMap sorting should be based on key but not based on values.

NavigableMap

NavigableMap is a child Interface of SortedMap It provides several methods for Navigable purposes.

These Interfaces along with their various implementation and utility classes, Form the foundation of the Java Collection Framework.

Similar Java Tutorials

Leave a Comment