Saturday, 26 April 2014

TreeSet : isEmpty

boolean isEmpty():
Returns true, if the set contains no elements else return false.

import java.util.*;

class TreeSetIsEmpty{
 public static void main(String args[]){
  TreeSet<Integer> mySet1 = new TreeSet<> ();
  TreeSet<Integer> mySet2 = new TreeSet<> ();
  
  /* Add Elements too mySet */
  for(int i=20; i>0; i-=2){
   mySet1.add(i);
  }
  
  System.out.println("Is mySet1 empty " + mySet1.isEmpty());
  System.out.println("Is mySet2 empty " + mySet2.isEmpty());
 }
}

Output
Is mySet1 empty false
Is mySet2 empty true



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment