Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Collections.singletonList(value) when your code must work on Java 8 or the one element may be null. Use List.of(value) on Java 9 and later when nulls should be rejected and you want Java’s collection factory API. Both return lists that reject structural changes.

How the two singleton-list methods differ

Comparison Collections.singletonList(value) List.of(value)
Available since Java 1.3 Java 9
Null element Permitted by the method contract Rejected with NullPointerException
Cardinality Exactly one element One element with this overload; the factory also supports zero or multiple elements
Mutation Immutable; structural changes are rejected Unmodifiable; structural changes are rejected
Serialization The returned list is serializable Serializable when all elements are serializable
Access and identity Not specified here as value-based or as implementing RandomAccess Implements RandomAccess and is value-based

These guarantees come from Oracle’s Collections.singletonList API contract and the List API contract for the Java SE 26 documentation.

Does List.of allow null?

No. List.of(value) throws NullPointerException if value is null. Oracle’s contract for the List.of factories says they disallow null elements. Collections.singletonList(value) has no corresponding null prohibition in its method contract, so use it when a singleton list must contain null.

Are either of these lists mutable?

No. Both factory results reject structural changes such as adding or removing elements. If the caller needs to add, remove, or replace elements, make a mutable copy:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
List<String> values = new ArrayList<>(List.of("one"));
values.add("two");

The example requires Java 9 or later because it uses List.of. For Java 8, use new ArrayList<>(Collections.singletonList("one")).

Which method works in Java 8?

Collections.singletonList is documented since Java 1.3, so it is available in Java 8. List.of was introduced in Java 9 and cannot be used when compiling against Java 8 APIs.

Can List.of create one element—or more?

Yes. Its one-argument overload creates a one-element list, and its factory family includes zero-element and multiple-element forms. Collections.singletonList is specifically for exactly one element. For example:

List<String> none = List.of();
List<String> one = List.of("one");
List<String> several = List.of("one", "two", "three");

The varargs overload has a special consideration when an array is intended to be the single list element. Use an explicit type witness so the array is treated as one element:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
String[] array = {"one", "two"};
List<String[]> oneArray = List.<String[]>of(array);

See Oracle’s one-element overload and varargs overload documentation.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What do value-based and serialization guarantees mean?

Do not rely on List.of object identity

Oracle describes List.of results as value-based. Do not compare them with == to determine whether two lists are the same object, and do not synchronize on them; identity-sensitive behavior is not guaranteed.

Serialization depends on the factory and elements

The Collections.singletonList contract says its returned list is serializable. A List.of result is serializable when all of its elements are serializable. Neither guarantee means an element that is not serializable becomes serializable simply because it is in a list.

Which one should you choose?

  • Choose Collections.singletonList(value) for Java 8 compatibility, an API that specifically needs one element, or a singleton that may contain null.
  • Choose List.of(value) on Java 9 or later when values must be non-null and you want the same factory style for empty, singleton, and multi-element lists.
  • Wrap either result in new ArrayList<>(...) if the list must support structural changes.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.