-
怎么确保一个集合不能被修改
ArrayList<String> list = new ArrayList<>();list.add("x");Collection<String> clist = Collections.unmodifiableCollection(list);clist.add("y"); // 运行时出异常:java.lang.UnsupportedOperationExceptionSystem.out.println(list.size());
//
2022-10-14 17:32:47
怎么确保一个集合不能被修改
ArrayList<String> list = new ArrayList<>();list.add("x");Collection<String> clist = Collections.unmodifiableCollection(list);clist.add("y"); // 运行时出异常:java.lang.UnsupportedOperationExceptionSystem.out.println(list.size());
//