import java.util.Collections; import java.util.Hashtable; import java.util.Map; public class MainClass { public static void main(String[] s) { Hashtable table = new Hashtable(); table.put("key1", "value1"); table.put("key2", "value2"); table.put("key3", "value3"); Map m = Collections.unmodifiableMap(table); m.put("key3", "value3"); System.out.println(m); } }
Exception in thread "main" java.lang.UnsupportedOperationException at java.util.Collections$UnmodifiableMap.put(Collections.java:1286) at MainClass.main(MainClass.java:14)