Difference between Set and List in Java
Published in
3 min readJul 18, 2022
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.
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
.
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 areArrayList
,LinkedList
,Vector
,Stack
Set
implementations areHashSet
,LinkedHashSet
.