Online Java Compiler By
JavaTpoint.com
import java.util.*; public class CollectionsUnmodifiableSetExample2 { public static void main(String[] args) { Set
set = new TreeSet<>(); Collections.addAll(set, "Google", "Facebook", "Instagram"); System.out.println("Initial Set: " + set); Set
set2 = Collections.unmodifiableSet(set); System.out.println("Unmodifiable Set: " + set2); //Modifying the original set set.add("Twitter"); System.out.println("Unmodifiable Set: " + set2); } }
Output