方法调用返回指定映射的不可修改视图。当执行 m.put("key3", "value3"); 会提示java.lang.UnsupportedOperationException异常。
import java.util.*;
public class CollectionsDemo {
public static void main(String[] s) {
//object hashtable
Hashtabletable = new Hashtable();
// populate the table
table.put("key1", "value1");
table.put("key2", "value2");
table.put("key3", "value3");
System.out.println("Initial collection: "+table);
// create unmodifiable map
Map m = Collections.unmodifiableMap(table);
// try to modify the collection
m.put("key3", "value3");
}
}