Java ArrayList isEmpty() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
ArrayList

Definition

In Java, isEmpty() returns true if an ArrayList holds no elements, and false otherwise. It means exactly the same as size() == 0, but reads more clearly.

Check it before reading an element that might not exist, such as get(0). Note that a list holding a single null is not empty, and a null variable is not an empty list: calling isEmpty() on it throws NullPointerException.

An instance method of java.util.ArrayList (Java 1.2+): a resizable-array list with index access that allows null and duplicates and is not thread-safe.

Syntax

No arguments; returns a boolean.

Java
List<String> list = new ArrayList<>();
boolean e1 = list.isEmpty();     // true
list.add("x");
boolean e2 = list.isEmpty();     // false
CallWhat it does
list.isEmpty()true if the list has no elements.
!list.isEmpty()true if there is at least one element.
list == null || list.isEmpty()Null-safe check for a list that may be missing.
list.size() == 0Same result, less direct.

isEmpty() never changes the list and takes constant time.

Library declarations
Java
// java.util.ArrayList<E>
public boolean isEmpty()

// Declared in Collection<E> and List<E>

Parameters

ParameterDescription
NoneisEmpty() takes no parameters.

Return Value

Return ValueDescription
booleantrue if the size is 0; otherwise false.

Compare with Similar Methods

Related checks and resets:

MethodHow it differs
size()The exact count of elements.
clear()Removes everything, so isEmpty() becomes true.
getFirst()Throws on an empty list (Java 21+).
contains(o)Checks for a specific value instead.

Java Examples

Example 1 — Check a Cart Before and After Changes

Watch isEmpty() as an item is added and the list is cleared.

Java
import java.util.ArrayList;
import java.util.List;

public class ArrayListIsEmptyDemo {
    public static void main(String[] args) {
        List<String> cart = new ArrayList<>();
        System.out.println("empty at start? " + cart.isEmpty());

        cart.add("tea");
        System.out.println("after add? " + cart.isEmpty());

        cart.clear();
        System.out.println("after clear? " + cart.isEmpty() + " (size " + cart.size() + ")");
    }
}

How It Works

  1. New list. A freshly created ArrayList holds nothing, so isEmpty() is true.
  2. One item. After add("tea") the size is 1, so the answer flips to false.
  3. Cleared. clear() removes every element, making the list empty again.
  4. Same as size 0. The size printed next to it confirms that isEmpty() is simply size() == 0.

Example 2 — Guard get(0) with isEmpty()

Return a default value when there is no first element.

Java
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ArrayListIsEmptyGuard {
    public static void main(String[] args) {
        List<String> winners = new ArrayList<>();
        System.out.println("winner: " + firstOrDefault(winners, "no winner yet"));

        winners.addAll(Arrays.asList("Tara", "Uma"));
        System.out.println("winner: " + firstOrDefault(winners, "no winner yet"));
    }

    static String firstOrDefault(List<String> list, String fallback) {
        return list.isEmpty() ? fallback : list.get(0);
    }
}

How It Works

  1. Guard first. The helper checks isEmpty() before calling get(0), which would throw on an empty list.
  2. Fallback. With no winners yet, the helper returns the default text instead of failing.
  3. Data arrives. addAll adds Tara and Uma, so the list is no longer empty.
  4. First element. Now the helper returns get(0), which is Tara.

Example 3 — A null List vs an Empty List

Write a null-safe check and see that a list holding null is not empty.

Java
import java.util.ArrayList;
import java.util.List;

public class ArrayListIsEmptyNull {
    public static void main(String[] args) {
        List<String> missing = null;
        List<String> empty = new ArrayList<>();
        List<String> holdsNull = new ArrayList<>();
        holdsNull.add(null);

        System.out.println("missing: " + isNullOrEmpty(missing));
        System.out.println("empty: " + isNullOrEmpty(empty));
        System.out.println("holdsNull: " + isNullOrEmpty(holdsNull) + ", size " + holdsNull.size());
    }

    static boolean isNullOrEmpty(List<?> list) {
        return list == null || list.isEmpty();
    }
}

How It Works

  1. Short-circuit. list == null is checked first; when it is true, || skips isEmpty(), so no NullPointerException occurs.
  2. Empty list. A real list with no elements passes the null test and then reports isEmpty() as true.
  3. A null element counts. holdsNull contains one element whose value is null, so its size is 1 and it is not empty.
  4. Any element type. The List<?> parameter lets the helper accept a list of any element type.

Frequently Asked Questions

Call list.isEmpty(). It returns true when the list has no elements.
They give the same result. isEmpty() states the intent more clearly, so it is usually preferred.
No. A null element is still an element, so the size is 1 and isEmpty() returns false.
You get a NullPointerException. Use list == null || list.isEmpty() when the list may be missing.
Yes. After clear() the size is 0, so isEmpty() returns true.

Next: iterator()

Walk the list and remove safely while looping.

iterator() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful