Java: Understanding List, Set, Map, and Queue

Become familiar with the most used collection interfaces

Diego A. Rojas
Javarevisited

--

We can start defining a collection itself: A group of elements contained into a single one, for example:

Element: Yu-Gi-Oh card
Collection: Yugi’s deck (set of cards belonging to Yugi)

In programming, the idea is the same. You could have a single object or a group of the same object inside a collection. Specifically in Java, a collection refers to any group of objects stored in a single structure belonging to some class stored in java.util. There is 4 main collection interfaces you should be familiar with:

  • List
  • Set
  • Map
  • Queue

All of those interfaces extend from the main interface Collection, except the Map interface. Map is a different type, with its own purpose. Let’s start exploring the Collection interface’s methods:

  • add(E Element) : Boolean, inserts a new element.
  • remove(E Element) : Boolean, removes an element from the collection.
  • isEmpty() : Boolean, returns true if the collection has no elements.
  • size() : Returns how many elements we have stored in the collection.

--

--

Diego A. Rojas
Javarevisited

Improving people's life through code | Co-Founder at @HalloID