Interfaces & Classes in Java Collections Framework

Nimasha Madhushani
4 min readFeb 2, 2024
image by author

Hi Java lovers😌,

I think you have already read part 01 of this Java collections framework article series. If not here is the link: Java Collection Framworks — Part 01.

Let’s continue…

🔷Collection Interface

Collections have ‘n’ no: of interfaces.

🔷Main Interfaces

The Collection Interface is the main interface. It is the root interface for all other collection-related interfaces and cases. It also includes common methods that can be used for other collection objects.

image by author
  • A group of objects is a collection. In the above image, you can see that there are multiple objects represented in a single entity.
  • Adding an object, removing an object, and verifying an existing object can be done using a set of methods. Those methods are included inside the collection interface. So, the methods defined inside the collection interface are common across all classes in the collection.
  • Collection(I) is purely an interface.

Then, what are the Collections in Java?

In Java, we have a package called java.utils. So, this collections is a pre-defined class inside this package.

  • Collections class includes a set of methods. So, these methods inside the collections can be used for performing the operations inside collection objects.

Example,

  • Assume that ArrList is an array list. An array list is a collection object. Elements 1,2,3 are different objects inside this array list. If we need to sort the elements inside the array list, we can use collections class. There is a utility method called sort is available inside this collections class. Therefore, we can do the sort as Collections.sort(ArrList);
image by author

🎯Summary

  • The collection is an interface that comes under the collections framework.
  • Collections is a pre-defined class containing a set of utility methods.
  • Collections call is available in the java.utils package
image by author
image by author
  • List, Set, and Queue are the children of the Collection interface.
  • These child interfaces are implemented using different classes.

🔷List Interface

The list is a collection in which we can store a group of elements/objects.

  • The root interface of the List interface is the Collection interface. So, the List is a child interface.

⚡Features in List concept,

  • Insertion order should be preserved
  • Duplicate elements are allowed

⚡The list interface is implemented using different classes. They are,

  • ArrayList Class
  • LinkedList Class
  • Vector Class — Stack Class (Legacy Classes)

🔷Set Interface

The Set interface is a child of the Collection interface.

⚡Features in Set concept,

  • Insertion order is not preserved
  • Duplicate elements are not allowed

⚡The set interface is implemented using different classes. They are,

  • HashSet
  • LinkedHashSet

🔷Queue Interface

The Queue interface is a child of the Collection interface.

⚡Features in Queue concept,

  • Queues follow the FIFO(First In First Out) concept.
  • Queue concept is applied for the objects that are prior to processing.

⚡The queue interface is implemented using different classes. They are,

  • PriorityQueue Class (used to implement the queue interface)

🔷Map Interface

Independent from the Collection interface. So, the map is not a child of the Collection interface.

⚡Features in map concept,

  • Duplicates are not allowed for keys, and duplicates are allowed for values. So, keys are unique.
  • Each key is an object, and each value is also an object.
image by author

⚡The map interface is implemented using different classes. They are,

  • HashMap
  • LinkedHashMap

Yeah…!

I think we have discussed a lot in this article. So, I thought to have a little break here. Hope you will count fingures to enjoy the next article. Then, stay tuned guys…

Thank you for reading this.

Bye bye…👋🏼👋🏼

--

--