Collections Are the Best, Here Is Why You Should Use Them

What are collections

Jesse Nerio
Javarevisited
Published in
6 min readApr 10, 2024

--

Collections are very similar across the different programming languages. They involve the same data structures, the same functions and essentially look the same in every language.

If you are learning collections, just know you are learning it for all languages so be encouraged about learning these data types.

In every language they are a library of data structures used in every day programming. They are called collections because each data structure is a collection of objects. These collections manipulate memory in a certain way. They are implementations of stacks, queues, maps, lists, etc, given to you for your convenience.

The way you manipulate memory is structured by its collection type. A stack for example is LIFO (Last-In-First-Out). Let’s look at this in Java:

import java.util.Stack;

Stack<Integer> stack = new Stack<>();
stack.push(1);
stack.push(2);
stack.push(3);
System.out.println(stack.pop()); // Outputs 3

The key part, stack already exists in the collections library. java.util.* has all the collections inside it. You do not have to implement any collections. They come with the functions and inner data structures. They are meant to make your problem solving easier.

--

--

Jesse Nerio
Javarevisited

Hello, I am a self-taught programmer with a college background. My content is written with the purpose of making you into a better programmer. Share & follow :D