Java Collection Tutorial - Java ArrayList.isEmpty()


ArrayList.isEmpty() has the following syntax.

public boolean isEmpty()


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

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

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

    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.