标签:cli strong alt 异常 col support list lis 修改
怎么确保一个集合不能被修改
ArrayList<String> list = new ArrayList<>();
list.add("x");
Collection<String> clist = Collections.unmodifiableCollection(list);
clist.add("y"); // 运行时出异常:java.lang.UnsupportedOperationException
System.out.println(list.size());
//
标签:cli strong alt 异常 col support list lis 修改
原文地址:https://www.cnblogs.com/heliusKing/p/10659496.html