Java Collections emptyList() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Java 5+

Definition

In Java, Collections.emptyList() returns a List with no elements that can never be changed. It is the standard thing to return from a method that has nothing to give back, so callers can loop over the result without checking for null.

Because nobody can modify it, the JDK can hand out one shared instance to every caller, so it costs no memory per call. In Java 9 and later, List.of() gives a similar immutable empty list.

A static method of the java.util.Collections utility class, available since Java 5. Call it on the class name, as in Collections.emptyList(...), after import java.util.Collections;. You never create a Collections object.

Syntax

Call it with no arguments; the element type is inferred from where the result goes.

Java
List<String> none = Collections.emptyList();          // []
List<Integer> zero = Collections.<Integer>emptyList(); // explicit type witness
return Collections.emptyList();                        // in a method returning List<T>
CallWhat it does
Collections.emptyList()Shared immutable empty list.
Collections.<T>emptyList()Same, with the element type written out.
new ArrayList<>()An empty list you can add to.
List.of()Java 9+ immutable empty list.

The older constant Collections.EMPTY_LIST (Java 1.2) is the same kind of list but raw-typed, so it causes unchecked warnings. Prefer the generic method emptyList().

Library declarations
Java
// java.util.Collections
public static final <T> List<T> emptyList()

public static final List EMPTY_LIST   // raw constant, older style

Parameters

ParameterDescription
NoneemptyList() takes no parameters.

Return Value

Return ValueDescription
List<T>An empty, immutable list. size() is 0 and every change method throws.

Compare with Similar Methods

Ways to get a list with nothing in it:

MethodHow it differs
new ArrayList<>()Changeable; a new object every time.
singletonList(x)Immutable list with exactly one element.
nCopies(0, x)Also an immutable empty list, but less clear.
unmodifiableList(l)A read-only view of a list that may still change underneath.

Java Examples

Example 1 — Return an Empty List Instead of null

A lookup method returns emptyList() for an unknown customer, so the calling loop needs no null check.

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

public class CollectionsEmptyListLookup {
    static List<String> ordersFor(String customer) {
        if (customer.equals("ana")) {
            return Arrays.asList("book", "lamp");
        }
        return Collections.emptyList();
    }

    public static void main(String[] args) {
        for (String name : Arrays.asList("ana", "zed")) {
            List<String> orders = ordersFor(name);
            System.out.println(name + ": " + orders.size() + " orders " + orders);
            for (String o : orders) {
                System.out.println("  ship " + o);
            }
        }
    }
}

How It Works

  1. Known customer. For "ana" the method returns two orders, and the inner loop ships each one.
  2. Unknown customer. For "zed" it returns Collections.emptyList() rather than null.
  3. No special case. size(), printing, and the for loop all work on the empty list; the loop body simply never runs.

Example 2 — What You Can and Cannot Do

Reading methods work on the empty list; changing it or reading index 0 throws.

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

public class CollectionsEmptyListRules {
    public static void main(String[] args) {
        List<String> none = Collections.emptyList();
        System.out.println("isEmpty: " + none.isEmpty() + ", contains x: " + none.contains("x"));
        System.out.println("equals new ArrayList: " + none.equals(new ArrayList<String>()));

        try {
            none.add("x");
        } catch (UnsupportedOperationException e) {
            System.out.println("add: " + e.getClass().getSimpleName());
        }
        try {
            none.get(0);
        } catch (IndexOutOfBoundsException e) {
            System.out.println("get(0): " + e.getClass().getSimpleName());
        }
    }
}

How It Works

  1. Queries are fine. isEmpty() is true and contains is false for any value.
  2. Equal to other empty lists. List equality compares elements, so it equals an empty ArrayList.
  3. No adding. add throws UnsupportedOperationException because the list is immutable.
  4. No index 0. There are no elements, so get(0) is out of range.

Example 3 — Type Inference and the Shared Instance

Pass emptyList() straight into a method, with and without a type witness, and compare two empty lists of different types.

Java
import java.util.Collections;
import java.util.List;

public class CollectionsEmptyListShared {
    static int countLong(List<String> words) {
        int n = 0;
        for (String w : words) {
            if (w.length() > 5) {
                n++;
            }
        }
        return n;
    }

    public static void main(String[] args) {
        System.out.println(countLong(Collections.emptyList()));
        System.out.println(countLong(Collections.<String>emptyList()));

        List<String> a = Collections.emptyList();
        List<Integer> b = Collections.emptyList();
        System.out.println("Same object: " + ((Object) a == (Object) b));
    }
}

How It Works

  1. Inferred argument. Since Java 8, the compiler infers List<String> from the parameter type, so countLong(Collections.emptyList()) compiles.
  2. Explicit witness. Collections.<String>emptyList() spells out the type, which Java 7 code needed in argument position.
  3. One shared list. Casting both variables to Object allows an identity check, and current JDKs return the very same immutable instance for every element type.

Frequently Asked Questions

An empty, immutable List. Its size is 0 and any attempt to change it throws UnsupportedOperationException.
Callers can loop over it, call size(), or print it without a null check, which avoids NullPointerException.
No. Copy it first with new ArrayList<>(list) if you need a list you can change.
They behave the same, but EMPTY_LIST is a raw-typed constant and causes unchecked warnings. emptyList() is generic and type-safe.
Both return an immutable empty list. List.of() needs Java 9 or later; emptyList() works on every version since Java 5.

Next: emptyListIterator()

Get a ListIterator that has no elements (Java 7+).

emptyListIterator() 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.

14 people found this page helpful