集合

使用Arrays.asList创建的List无法添加元素。

Arrays.asList创建的List为Arrays的内部类。该类继承自AbstractList,未实现add方法

public void add(int index, E element) {
    throw new UnsupportedOperationException();
}

添加元素时,会抛出UnsupportedOperationException。

results matching ""

    No results matching ""