Friday 30 May 2014

ArrayList : isEmpty : Check Whether List is empty

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

import java.util.*;
class ArrayListEmpty{
 public static void main(String args[]){
  ArrayList<Double> myList = new ArrayList<> ();
  
  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