Java Collections singletonList() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
java.util.Collections

Definition

In Java, Collections.singletonList(o) returns a List of size 1 whose only element is o. The list is immutable: you cannot add, remove, or even replace that element.

Reach for it when a method wants a List but you only have one value, for example a single email recipient or a default choice. It is lighter than building an ArrayList for one item.

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

Syntax

Pass the single element.

Java
List<String> to = Collections.singletonList("[email protected]");
sendAll(to);                                         // a method that takes List<String>
String only = to.get(0);                             // "[email protected]"
CallWhat it does
Collections.singletonList(x)Immutable list [x].
Arrays.asList(x)Fixed-size list [x]; set(0, y) is allowed.
new ArrayList<>(Collections.singletonList(x))Changeable list starting with x.
List.of(x)Java 9+ immutable list; rejects null.

Added in Java 1.3. The returned list supports fast index access, so get(0) is instant; get(1) or any other index throws IndexOutOfBoundsException.

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

Parameters

ParameterDescription
oThe only element of the list. May be null.

Return Value

Return ValueDescription
List<T>An immutable list of size 1 containing o.

Compare with Similar Methods

Small immutable or fixed lists:

MethodHow it differs
singleton(x)One-element Set instead of a List.
emptyList()Immutable list with no elements.
nCopies(n, x)Immutable list of n copies of one value.
Arrays.asList(x)Fixed size, but set works.

Java Examples

Example 1 — Call a List Method with One Recipient

A mailing method takes a List of addresses. Send to a single person without building an ArrayList.

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

public class CollectionsSingletonListMail {
    static int send(List<String> recipients) {
        for (String r : recipients) {
            System.out.println("sending to " + r);
        }
        return recipients.size();
    }

    public static void main(String[] args) {
        int a = send(Arrays.asList("[email protected]", "[email protected]"));
        int b = send(Collections.singletonList("[email protected]"));
        System.out.println("sent " + a + " + " + b);
    }
}

How It Works

  1. List parameter. send accepts any List<String> and loops over it.
  2. Many recipients. The first call passes two addresses.
  3. Just one. The second call wraps a single address with singletonList, so the method sees a list of size 1.

Example 2 — singletonList vs Arrays.asList for One Element

Both look like [x], but only one lets you replace the element.

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

public class CollectionsSingletonListVsAsList {
    public static void main(String[] args) {
        List<String> fixed = Arrays.asList("old");
        fixed.set(0, "new");
        System.out.println("Arrays.asList after set: " + fixed);

        List<String> single = Collections.singletonList("old");
        try {
            single.set(0, "new");
        } catch (UnsupportedOperationException e) {
            System.out.println("singletonList set: " + e.getClass().getSimpleName());
        }
        try {
            single.get(1);
        } catch (IndexOutOfBoundsException e) {
            System.out.println("singletonList get(1): " + e.getClass().getSimpleName());
        }
    }
}

How It Works

  1. Fixed size, editable slot. Arrays.asList is backed by an array, so set(0, "new") just writes into it.
  2. Truly immutable. singletonList refuses set with UnsupportedOperationException.
  3. Only index 0. A one-element list has no index 1, so get(1) throws IndexOutOfBoundsException.

Example 3 — A Default Language When the User Picked None

Fall back to a one-item list, then make a changeable copy when more items must be added.

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

public class CollectionsSingletonListDefault {
    static List<String> languages(List<String> chosen) {
        return chosen.isEmpty() ? Collections.singletonList("en") : chosen;
    }

    public static void main(String[] args) {
        List<String> langs = languages(new ArrayList<String>());
        System.out.println("default: " + langs);

        List<String> editable = new ArrayList<>(langs);
        editable.add("fr");
        System.out.println("edited copy: " + editable + ", default still " + langs);
    }
}

How It Works

  1. Nothing chosen. The user's list is empty, so languages returns singletonList("en").
  2. Copy before editing. The default is immutable, so the code copies it into an ArrayList before adding "fr".
  3. Original untouched. The copy has two languages, while the singleton list still holds only "en".

Frequently Asked Questions

An immutable List of size 1 containing the element you pass.
No. Even set(0, value) throws UnsupportedOperationException.
Both have a fixed size of 1. Arrays.asList allows set; singletonList allows no changes at all.
Yes. singletonList(null) is a valid list of size 1. List.of(null) in Java 9+ would throw.
Copy it first: new ArrayList<>(singletonList) gives a list you can add to.

Next: singletonMap()

Create an immutable Map holding exactly one key-value pair.

singletonMap() 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