Example & Tutorial understanding programming in easy ways.

Which all classes implement Set interface?

A Set is a collection that contains no duplicate elements.

The sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element.
The are commonly three implement of Set interface these are:- HashSet,SortedSet and TreeSet.

SortedSet is an interface which extends Set.
As the name suggest, the interface allows the data to be iterated in the ascending order or sorted on the basis of Comparator or Comparable interface.
All elements inserted into the interface must implement Comparable or Comparator interface.
The class is not synchronized.

It is the implementation of SortedSet interface.
This implementation provides guaranteed log(n) time cost for the basic operations (add, remove and contains).
The class is not synchronized.

HashSet class implements the Set interface.
HashSet class is not synchronized.
HashSet class makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time.
HashSet class permits the null element.
HashSet class offers constant time performance for the basic operations (adds, remove, contains and size).

Read More →