Tuesday, 25 March 2014

IsEmpty() : Check Whether List is empty

boolean isEmpty()
    Returns true if this list contains no elements.


import java.util.*;
class ListEmpty{
 public static void main(String args[]){
  List<Double> myList = new LinkedList<> ();
  
  System.out.println("Number Of Elements in the List are " + myList.size());
  System.out.println("Is the List Empty " + myList.isEmpty());
  
  /* Add Elements to the List */
  myList.add(10.01);
  myList.add(null);
  myList.add(123.01);
  myList.add(null);
  
  System.out.println("Number Of Elements in the List are " + myList.size());
  System.out.println("Is the List Empty " + myList.isEmpty());
  System.out.println("Elements in the List are");
  System.out.println(myList);
 }
}

Output
Number Of Elements in the List are 0
Is the List Empty true
Number Of Elements in the List are 4
Is the List Empty false
Elements in the List are
[10.01, null, 123.01, null]


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment