Click here to watch in Youtube : https://www.youtube.com/watch?v=Ms7sEojiisI&list=UUhwKlOVR041tngjerWxVccwTreeSetExample.java import java.util.TreeSet;
/*
* Example of isEmpty() method.
*/
public class TreeSetExample
{
public static void main( String[] args )
{
TreeSet<Integer> treeSet = new TreeSet<Integer>();
System.out.println("treeSet : " + treeSet + "\n");
/*
* Returns true if this set contains no elements.
*/
boolean isEmpty = treeSet.isEmpty();
System.out.println("isEmpty : " + isEmpty + "\n");
treeSet.add(10);
treeSet.add(50);
treeSet.add(40);
treeSet.add(20);
treeSet.add(30);
System.out.println("treeSet : " + treeSet + "\n");
/*
* Returns true if this set contains no elements.
*/
isEmpty = treeSet.isEmpty();
System.out.println("isEmpty : " + isEmpty);
}
}
Output treeSet : []
isEmpty : true
treeSet : [10, 20, 30, 40, 50]
isEmpty : false