Set Concept Simplified In Java

Share and Enjoy !

Set: Set is again a child interface of collection got introduced in Java-1.2V.

The Set interface extends to the Collection interface and it contains the methods that are inherited from Collection interface. The Set interface does not allow the use of duplicate elements in a collection.Hence the add() method returns false if we add the duplicate element to the collection.

If we want to represent a group of objects as a single entity where duplicates are not allowed and insertion order is not preserved, In such case we must implement Set .

The classes extending Sets are…

  • HashSet(C-1.2V)
  • LinkedHashSet(C-1.4V)

The Interfaces extends sets are…

  • SortedSet(I-1.2V)
  • NavigableSet(I-1.6V)
  • TreeSet(C-1.2V)

Set interface doesn’t contain any new methods and hence we have to use only collection interface methods.

Share and Enjoy !

See also  Constant Concept Simplified in Java

Leave a Reply

Your email address will not be published. Required fields are marked *