ArrayList 变长数组

来源:互联网 发布:软件开发专业怎样 编辑:程序博客网 时间:2024/05/19 16:07


ArrayList相当于STL里面的Vector。

快速初始化的方法
ArrayList<Integer>  a=new ArrayList<Integer> (Arrays.asList(1,2,3,4,5));
注意函数Arrays.asList返回的是:类Arrays的静态内部类,该类定义见下:
 private static class ArrayList<E> extends AbstractList<E>
        implements RandomAccess, java.io.Serializable{
  public E remove(int index) {
        throw new UnsupportedOperationException();
    }
}
所以直接对返回结果的List进行remove()等操作有异常!



1 0