Difference between Set and List in Java

Asep Saputra
Code Storm
Published in
3 min readJul 18, 2022

--

Set vs List in Java
Photo by Tim Mossholder on Unsplash

Overview

Before we start I want to make an intermezo, is this a List or a Set?

Okay, whatever your answer is, it’s correct.

Then how about this, List or Set?

The answer is List.

Photo by Sander Sammy on Unsplash

If you already understand, you can skip this article or read to the end to correct it if something isn’t right. Or you can give suggestions via comments if there is something missing to convey.

Let’s get started!

Example

First let’s create a List as well as a Set.

Difference between Set and List in Java

From the code above we can see that List implements LinkedList and Set implements LinkedHashSet.

Besides LinkedList and LinkedHashSet there are many more, you can try it yourself. Among them:

  • List implementations are ArrayList, LinkedList, Vector, Stack
  • Set implementations are HashSet, LinkedHashSet.

--

--