---
title: "Discussion on \"Collections.unmodifiableList vs List.copyOf in Java\" | Hashnode"
description: "Discussion on \"Collections.unmodifiableList vs List.copyOf in Java\". Discover why Collections.unmodifiableList isn't truly immutable and how to use List.copyOf in Java to create isolated, read-only collection snapshots."
url: "https://hashnode.com/posts/collections-unmodifiablelist-vs-list-copyof/6ad40dd4ee88dde844dbc975"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Collections.unmodifiableList vs List.copyOf in Java](https://doogal.dev/collections-unmodifiablelist-vs-list-copyof?utm_source=hashnode&utm_medium=feed)

Discover why Collections.unmodifiableList isn't truly immutable and how to use List.copyOf in Java to create isolated, read-only collection snapshots.

Oct 18 · 4 min read · doogal.dev  
Read the article

-   [#java](https://hashnode.com/tag/java)
-   [#softwareengineering](https://hashnode.com/tag/softwareengineering)
-   [#programming](https://hashnode.com/tag/programming)
-   [#backend](https://hashnode.com/tag/backend)

## Written by

[Doogal Simpson](https://hashnode.com/@doogal)

@doogal

  
[View profile](https://hashnode.com/@doogal)

"hey doogal, what is .... ?"

## Responses 2

Markdown supported · ⌘↵ to post

[SMTasker](https://hashnode.com/@smtasker)

[Oct 29](https://hashnode.com/posts/collections-unmodifiablelist-vs-list-copyof/6ad40dd4ee88dde844dbc975/comment/6ae353a4e5d6eb2076a9f124)

A useful regression test would separate structural changes from element changes: add an item to the source list, then mutate a field on an object already in it. The first should leave a List.copyOf snapshot unchanged; the second exposes the shallow-copy boundary you describe. For a queued job, immutable element records matter just as much as the list wrapper.

[mno tao](https://hashnode.com/@dancermno)

[Oct 18](https://hashnode.com/posts/collections-unmodifiablelist-vs-list-copyof/6ad40dd4ee88dde844dbc975/comment/6ad4371d1d93d6dd9f36d689)

Two things worth knowing before swapping one for the other: List.copyOf rejects null elements with a NullPointerException, so a list with nulls that used to pass through unmodifiableList fine can start failing at the copy. And when the argument is already an immutable list from List.of or List.copyOf, it returns the same instance instead of copying, so defensive copies at every layer cost almost nothing.

Stream.toList() from Java 16 sits in between: unmodifiable, but it does allow nulls.
