Java Set

The Set interface of the Java Collections framework provides the features of the mathematical set in Java. It extends the Collection interface. Unlike the List interface, sets cannot contain duplicate elements. Since Set is an interface, we cannot create objects from it. In order to use functionalities of the Set interface, we can use these classes:

  1. HashSet
  2. LinkedHashSet
  3. EnumSet
  4. TreeSet

These classes are defined in the Collections framework and implement the Set interface. The Set interface is also extended by these subinterfaces:

  1. SortedSet
  2. NavigableSet

In Java, we must import java.util.Set package in order to use Set.



Subsections