// Collection<Integer> integers = new ArrayList<Integer>();//(Arrays.asList(1,2,3,4,5));
Collection<Integer> integers = new ArrayList<Integer>(Arrays.asList(1,2,3,4,5));
// integers = Arrays.asList(1,2,3,4,5);
System.out.println(integers.toString());
Integer[] i = { 6,7,8,9,10};
// integers = Arrays.asList(i);
// System.out.println(integers.toString());
integers.addAll(Arrays.asList(i));
注释第二句,使用第一三句会抛出异常 java.lang.UnsupportedOperationException,Thinking in java 解释说Arrays.asList()输出的List底层是数据,不能调整尺寸。
时间: 2024-12-21 09:46:18