Set Interface in Java

The Set interface also extends the Collection interface but does not add any methods to it. Collection classes which implement the Set interface have the add stipulation that Sets CANNOT contain duplicate elements.Elements are compared using the equals method.But List allows duplicate elements.Set is an unordered collection. 

Java provides 2 concrete classes which implement the Set interface
  1. HashSetHashSet behaves like a HashMap except that the elements cannot be duplicated.
  2. TreeSetTreeSet behaves like TreeMap except that the elements cannot be duplicated.

Search: