Online Java Compiler By
JavaTpoint.com
import java.util.*; public class CollectionsUnmodifiableSetExample1 { public static void main(String[] args) { Set<Integer> set = new TreeSet<>(); Collections.addAll(set, 1,2,3,4,5); System.out.println("Initial Set: " + set); Set<Integer> set2 = Collections.unmodifiableSet(set); System.out.println("Unmodifiable Set: " + set2); //Modifying the original set set.add(15); System.out.println("Unmodifiable Set: " + set2); } }
Output