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>
Call
What 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
Parameter
Description
None
emptyList() takes no parameters.
Return Value
Return Value
Description
List<T>
An empty, immutable list. size() is 0 and every change method throws.
Queries are fine.isEmpty() is true and contains is false for any value.
Equal to other empty lists. List equality compares elements, so it equals an empty ArrayList.
No adding.add throws UnsupportedOperationException because the list is immutable.
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));
}
}
Output
0
0
Same object: true
How It Works
Inferred argument. Since Java 8, the compiler infers List<String> from the parameter type, so countLong(Collections.emptyList()) compiles.
Explicit witness.Collections.<String>emptyList() spells out the type, which Java 7 code needed in argument position.
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.