The add() method of NavigableSet in Java is used to add a specific element into a NavigableSet collection. The function adds the element only if the specified element is not already present in the NavigableSet else the function return False if the element is already present in the NavigableSet.
boolean add(E element) Where, E is the type of element maintained by this NavigableSet collection.
Parameters: The parameter element is of the type of element maintained by this NavigableSet and it refers to the element to be added to the NavigableSet.
Return Value: The function returns True if the element is not present in the NavigableSet and is new, else it returns False if the element is already present in the NavigableSet.
Note: The add() method of NavigableSet interface in java is inherited from the Set interface.
Below programs illustrate the use of Java.util.NavigableSet.add() method:
NavigableSet: [4, Geeks, NavigableSet, To, Welcome]
NavigableSet: [10, 20, 30, 40, 50, 60]
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.