ArrayList isEmpty() method in java

Let’s learn ArrayList isEmpty() method in java.

ArrayList isEmpty() method in java

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

Syntax:

ArrayList.isEmpty()

Parameter:

this method does not accept any parameter.

Throws:

this method does not have any exceptions.

Also read – ArrayList in java

Now let’s see example on ArrayList isEmpty() method.

import java.util.ArrayList;
public class ArrayListIsEmptyMethodExample
{
   public static void main(String[] args)
   {
      ArrayList<Integer> al = new ArrayList<Integer>();
      // before checking ArrayList using isEmpty() method
      System.out.println("Is ArrayList empty: " + al.isEmpty());
      al.add(86);
      al.add(25);
      al.add(53);
      al.add(85);
      // after checking ArrayList using isEmpty() method
      System.out.println("Is ArrayList empty: " + al.isEmpty());
      for(Integer num : al)
      {
         System.out.println(num);
      }
   }
}


Output:

Is ArrayList empty: true
Is ArrayList empty: false
86
25
53
85