interface Set Tutorial


The Set interface exactly fits into collections interfaces hierarchy and thereby it is a part of collections framework. The very very important characteristic of Set is it does not allow duplicate elements. It allows null elements. But it permits only one null element as set does not allow duplicates. The Set interfaces comes with two important subclasses – HashSet and TreeSet. HashSet constructors are overloaded that can take different capacities and load factors. TreeSet object cannot be created as tree is balanced always.

Following is the interface signature

public interface Set extends Collection

The Set interface does not add any new methods but overridden many methods of Collection interface with its own functionality.

Programming Tip: The Set methods throw either NullPointerException or ClassCastException when an ineligible (not acceptable) element is tried to add.

1 thought on “interface Set Tutorial”

Leave a Comment

Your email address will not be published.