java集合框架01
List 接口存储一组不唯一(可以重复),有序(插入顺序)的对象 01. ArrayList实现了长度可变的数组,在内存中分配连续的空间。遍历元素和随机访问元素的效率比较高 通过看ArrayList的源码得知: /** * Constructs an empty list with an initial capacity of ten. 构造一个初始容量为十的空列表 */ public ArrayList() { this(10); 调用带参的构造 参数为10 } ArrayList创建的时候,数组初始化长度为10! List list=new ArrayList(-1); 这句话会运行错误! 看源码得知! /** * Constructs an empty list with the specified initial capacity. * * @param initialCapacity the initial capacity of the list * @exception IllegalArgumentException if the specified initial capacity * is negative */ public ArrayList(int initialCapacity) { super(); if (initialCapacity < 0) /