1. 怎么确保一个集合不能被修改

     java面试记录-LMLPHP

    ArrayList<String> list = new ArrayList<>();list.add("x");Collection<String> clist = Collections.unmodifiableCollection(list);clist.add("y"); // 运行时出异常:java.lang.UnsupportedOperationExceptionSystem.out.println(list.size());
     // 
04-02 18:52