NavigableSet isEmpty() method in Java

The java.util.NavigableSet.isEmpty() method is used to check if a NavigableSet is empty or not. It returns True if the NavigableSet is empty otherwise it returns False.


boolean isEmpty()

Parameters: This method does not take any parameter

Return Value: The method returns True if the NavigableSet is empty else returns False.

Below program illustrate the java.util.NavigableSet.isEmpty() method:





// Java code to illustrate isEmpty()
import java.util.*;
public class NavigableSetDemo {
    public static void main(String args[])
        // Creating an empty NavigableSet
        NavigableSet<String> st = new TreeSet<String>();
        // Use add() method to add elements into
        // the NavigableSet
        // Displaying the NavigableSet
        System.out.println("NavigableSet: " + st);
        // Check for the empty NavigableSet
        System.out.println("Is the NavigableSet empty? "
                           + st.isEmpty());
        // Clearing the NavigableSet using clear() method
        // Again Checking for the empty NavigableSet
        System.out.println("Is the NavigableSet empty? "
                           + st.isEmpty());



NavigableSet: [4, Geeks, To, Welcome]
Is the NavigableSet empty? false
Is the NavigableSet empty? true

Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.