To understand what a set is, let’s understand what collections are.
A collection is a group of elements bundled into one instance. This can be a set, an arraylist, a linkedlist or a map. Each represents a different way to handle all these elements
A set is a collection that cannot contain duplicate elements.
Hm….what does that mean? Sounds straightforward but aren’t all elements unique in a sense?
It means in a set there will never exist two values in the same set.
Let’s take this array as an example: [1,3,3,4,2,5]. If we insert this array into the set, the set will contain [1,3,4,2,5] as its values.
#java8 #java #data-structures