Set is an interface that extends the collection interface. Duplicate values cannot be contained in a set. The values in a set are not stored in an ordered manner and hence these values cannot be accessed using an index. There are three different classes that implement the Set interface:
- HashSet:
- Stores elements by using hashing a mechanism
- An index cannot be used to access values
- Can contain unique elements only
- LinkedHashSet
- Maintains the insertion order
- TreeSet
- Maintains ascending order
There are methods available in the Set interface, such as add(), contains(), isEmpty(), iterator(), remove(), size(), and so on, out of which we will be looking at an iterator.