Tuesday, 27 May 2014

LinkedList : isEmpty : Check Whether List is empty

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

import java.util.*;
class LinkedListEmpty{
 public static void main(String args[]){
  LinkedList<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());
 }
}

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


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment