Returns an unmodifiable view (read-only) of the specified collection. Attempts to modify the returned collection, whether direct or via its iterator, result in an UnsupportedOperationException.
Since the collection created by this method is a view of the original collection, modifying the original will reflect the changes in it:

package com.logicbig.example.collections;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
public class UnmodifiableCollectionExample {
public static void main(String... args) {
Collection<String> c = new ArrayList<>();
Collections.addAll(c, "a", "b", "c");
System.out.println("Original collection: " + c);
Collection<String> c2 = Collections.unmodifiableCollection(c);
System.out.println("Unmodifiable Collection: " + c2);
c.add("d");
System.out.println("Unmodifiable Collection after adding element to the ordinal one:");
System.out.println(c2);
}
}
Output
Original collection: [a, b, c]
Unmodifiable Collection: [a, b, c]
Unmodifiable Collection after adding element to the ordinal one:
[a, b, c, d]
JDK 25
Since this method returns 'read-only' collection, modifying itself will throw the exception:

package com.logicbig.example.collections;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
public class UnmodifiableCollectionExample2 {
public static void main(String... args) {
Collection<String> c = new ArrayList<>();
Collections.addAll(c, "a", "b", "c");
Collection<String> c2 = Collections.unmodifiableCollection(c);
c2.add("d");
}
}
Output
java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableCollection.add (Collections.java:1093)
at com.logicbig.example.collections.UnmodifiableCollectionExample2.main (UnmodifiableCollectionExample2.java:19)
at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:104)
at java.lang.reflect.Method.invoke (Method.java:565)
at org.codehaus.mojo.exec.AbstractExecJavaBase.executeMainMethod (AbstractExecJavaBase.java:402)
at org.codehaus.mojo.exec.ExecJavaMojo.executeMainMethod (ExecJavaMojo.java:142)
at org.codehaus.mojo.exec.AbstractExecJavaBase.doExecClassLoader (AbstractExecJavaBase.java:377)
at org.codehaus.mojo.exec.AbstractExecJavaBase.lambda$execute$0 (AbstractExecJavaBase.java:287)
at java.lang.Thread.run (Thread.java:1474)
JDK 25