Online Java Compiler By
JavaTpoint.com
import java.util.*; public class CollectionsUnmodifiableListExample3 { public static void main(String[] args) { ArrayList
list = new ArrayList<>(); list.add(10); list.add(20); list.add(30); list.add(40); List
list2 = Collections.unmodifiableList(list); System.out.println("Unmodifiable list: " + list2); list.add(50); System.out.println("Unmodifiable list after adding (50): "+list); } }
Output