TreeSet isEmpty Example

TreeSet class isEmpty example. This example shows you how to use isEmpty method.


TreeSet class isEmpty example. public boolean isEmpty() Returns true if this set contains no elements.

Here is the code

/**
 * @ # IsEmpty.java
 * A class repersenting use to isEmpty method 
 * of TreeSet class in java.util package
 * version 23 May 2008
 * author Rose India 
 */
import java.util.*;

public class IsEmpty {

    public static void main(String[] args) {

        // Create a new TreeSet object:
        TreeSet ts = new TreeSet();

        System.out.println("TreeSet is empty " + ts.isEmpty());


        // Add the elements to the set and display it:
        ts.add(10);
        ts.add(19);
        ts.add(5);

        System.out.println("TreeSet is empty " + ts.isEmpty());

        System.out.println("ts = " + ts);
    }
}

Output
TreeSet is empty true
TreeSet is empty false
ts = [5, 10, 19]

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US