Java Collections synchronizedList() Method

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

Definition

In Java, Collections.synchronizedList(list) returns a List wrapper in which every method, including index-based ones like get(i) and set(i, x), holds a lock while it runs.

The usual idiom is Collections.synchronizedList(new ArrayList<>()): create the list inside the call, so the only reference anyone has is the safe wrapper.

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

Syntax

Create and wrap in one expression.

Java
List<Integer> ids = Collections.synchronizedList(new ArrayList<Integer>());
ids.add(7);                       // thread-safe
synchronized (ids) {              // required for iteration
    for (int id : ids) { /* ... */ }
}
CallWhat it does
ids.add(x) / get(i) / set(i, x)Each call is atomic.
ids.sort(cmp) / replaceAll(op)Java 8 bulk methods lock for you.
synchronized (ids) { new ArrayList<>(ids) }A consistent snapshot.
synchronized (ids) { for ... }Iteration must be manually locked.

Available since Java 1.2. If the original list implements RandomAccess (like ArrayList), the wrapper does too. For lists that are read far more often than written, CopyOnWriteArrayList from java.util.concurrent is an alternative.

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

Parameters

ParameterDescription
listThe list to make thread-safe. Do not keep using it directly.

Return Value

Return ValueDescription
List<T>A synchronized view of list.

Compare with Similar Methods

Related wrappers:

MethodHow it differs
synchronizedCollection(c)For collections that are not lists.
unmodifiableList(l)Read-only list view.
checkedList(l, type)Type-checked list; can be combined with this wrapper.

Java Examples

Example 1 — Four Threads Filling One List

Each thread adds its own block of 250 IDs. Afterwards, sort and check the ends.

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

public class CollectionsSynchronizedListWorkers {
    public static void main(String[] args) throws InterruptedException {
        List<Integer> ids = Collections.synchronizedList(new ArrayList<Integer>());
        List<Thread> workers = new ArrayList<>();
        for (int t = 0; t < 4; t++) {
            final int start = t * 250;
            Thread th = new Thread(() -> {
                for (int i = start; i < start + 250; i++) {
                    ids.add(i);
                }
            });
            workers.add(th);
            th.start();
        }
        for (Thread th : workers) {
            th.join();
        }
        Collections.sort(ids);
        System.out.println("size " + ids.size() + ", first " + ids.get(0) + ", last " + ids.get(ids.size() - 1));
    }
}

How It Works

  1. Separate ranges. Thread 0 adds 0-249, thread 1 adds 250-499, and so on, all into the same wrapper.
  2. Arrival order varies. The threads interleave, so the list is unsorted after joining. Collections.sort calls the wrapper's sort, which locks internally.
  3. Nothing lost. All 1000 IDs are present, from 0 to 999.

Example 2 — Take a Snapshot Under the Lock

Copy a chat history while holding the lock, then keep using the copy without blocking other threads.

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

public class CollectionsSynchronizedListSnapshot {
    public static void main(String[] args) {
        List<String> chat = Collections.synchronizedList(new ArrayList<String>());
        chat.add("hi");
        chat.add("hello");
        chat.add("bye");

        List<String> copy;
        synchronized (chat) {
            copy = new ArrayList<>(chat);
        }
        chat.add("later");

        System.out.println("snapshot " + copy);
        System.out.println("live     " + chat);
    }
}

How It Works

  1. Short critical section. The lock is held only long enough to copy the three messages.
  2. Work outside the lock. Code can loop over copy freely; other threads are not blocked meanwhile.
  3. Independent. The later message reaches the live list but not the snapshot.

Example 3 — Writing to the Original List Skips the Lock

The wrapper only protects calls that go through it. Keeping a reference to the raw list is a common mistake.

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

public class CollectionsSynchronizedListBypass {
    public static void main(String[] args) {
        List<String> raw = new ArrayList<>();
        List<String> safe = Collections.synchronizedList(raw);

        safe.add("through wrapper");
        raw.add("behind its back");
        System.out.println("wrapper sees: " + safe);
        System.out.println("same data? " + (raw.size() == safe.size()));

        List<String> better = Collections.synchronizedList(new ArrayList<String>());
        better.add("only path");
        System.out.println("idiom: " + better);
    }
}

How It Works

  1. One list, two doors. safe and raw point at the same storage; only safe takes the lock.
  2. Unlocked write. raw.add works in this single-threaded demo, but in a multi-threaded program it could corrupt the list while another thread uses safe.
  3. Safer idiom. Creating the ArrayList inside the call leaves no raw reference to misuse.

Frequently Asked Questions

It returns a List wrapper in which every method call holds a lock, making single operations thread-safe.
Wrap the loop in synchronized (list) { ... } using the wrapper as the lock.
So no code keeps a reference to the unsynchronized ArrayList and bypasses the lock.
synchronizedList suits frequent writes; CopyOnWriteArrayList suits mostly-read lists and iterates without locking.
Yes. In Java 8+, Collections.sort calls the wrapper's sort method, which holds the lock.

Next: synchronizedMap()

Wrap a Map so each method call is thread-safe.

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

7 people found this page helpful