Java ArrayList.isEmpty()

Syntax

ArrayList.isEmpty() has the following syntax.

public boolean isEmpty()

Example

In the following code shows how to use ArrayList.isEmpty() method.


/*  ww w .  j a  v  a  2s. c o  m*/
import java.util.ArrayList;

public class Main {
   public static void main(String[] args) {
      
    ArrayList<Integer>  arrlist = new ArrayList<Integer> (5);

    arrlist.add(25);        
           
    boolean retval = arrlist.isEmpty();
    if (retval == true) {
      System.out.println("list is empty");
    } else {
      System.out.println("list is not empty");
    }

  }
}

The code above generates the following result.