What does the method isEmpty() do in java?

Java 8Object Oriented ProgrammingProgramming

The isEmpty() method of the class java.util.ArrayList returns true if this list contains no elements.

Example

import java.util.ArrayList;
public class ArrayListDemo {
   public static void main(String[] args) {
      ArrayList<Integer> arrlist = new ArrayList<Integer>(5);
      arrlist.add(25);
      arrlist.add(10);
      arrlist.add(20);
      arrlist.add(35);
      boolean retval = arrlist.isEmpty();
      if (retval == true) {
         System.out.println("list is empty");
      } else {
         System.out.println("list is not empty");
      }
      for (Integer number : arrlist) {
         System.out.println("Number = " + number);
      }
   }
}

Output

list is not empty
Number = 25
Number = 10
Number = 20
Number = 35
raja
Published on 16-Jan-2018 12:35:20
Advertisements