Java TreeSet.isEmpty()

Syntax

TreeSet.isEmpty() has the following syntax.

public boolean isEmpty()

Example

In the following code shows how to use TreeSet.isEmpty() method.


/*  w w w . j  a  va 2  s  . c  o m*/
import java.util.TreeSet;

public class Main {
   public static void main(String[] args) {
     
     TreeSet <Integer> treeadd = new TreeSet<Integer> ();
     
     System.out.println(treeadd.isEmpty()); 
     
     treeadd.add(2);
     
     System.out.println(treeadd.isEmpty());  
   }     
}

The code above generates the following result.