Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


Collections in Java

Educative Answers Team

Just like you can take a box and put multiple items in it and still call it one unit, the same way you can take individual objects, group them together and call them a collection.

In Java, along with collections, a collection framework was introduced. This framework then takes several classes, interfaces and represents them as a single unit. Hence, it combines the collections so that they can be manipulated and worked on together. These are found in the java.util package.

The collections framework

The framework consists of three categories of collections:

1. Collection classes: These include different type of classes that can be used as they are or used to enhance and create a customized class.

2. Collection interfaces: This is the part of the framework that represents a collection i.e. it provides different type of interfaces for the collections and relevant methods that can be used by a collection.

3. Collection algorithms: This consists of several algorithms that a collection can use on the collection classes.

Let’s look at the different objects and methods available in each category in the illustration below.

Why use collections framework?

Using a collection framework has multiple advantages over disjointed data structures that have separate interfaces and functions. Let’s look at a few of these advantages:

  • Unifies multiple structures: This results in different structures and classes being grouped together and hence, they have the same interfaces and methods, therefore, reducing the burden on the designing process for these structures.

  • Improves durability: These collections consist of code i.e. classes, algorithms, and interfaces that have been rigorously tested and hence are robust.

  • Improves speed and performance: The implementations of the algorithms and methods have been tested to ensure that they are high-performance in order to improve the quality of the code.

  • Easy to remember: The structures follow a similar pattern and structure, hence they are easier for the programmer to remember and are built-in so, the need to write classes, algorithms and remember them is made redundant.


Copyright ©2022 Educative, Inc. All rights reserved

View all Courses

Keep Exploring