![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
List
junlouyu
默语
展开
-
ArrayList原理学习(三)
ArrayList原理学习(三) ArrayList删除指定索引范围的元素方法 protected void removeRange(int fromIndex, int toIndex) { // 当前集合修改次数++ modCount++; // 获取到toIndex后存在元素个数 int numMoved = size - toIndex; // 将toIndex后存在的元素复制到formIndex索引后,即将后面元素向前移动toIndex-fromIndex原创 2021-10-20 17:27:30 · 103 阅读 · 0 评论 -
ArrayList原理学习(二)
ArrayList原理学习(二) ArrayList构造方法 无参构造 public ArrayList() { // 调用无参构造方法时,申明了一个空的数组,此时该数组没有容量 this.elementData = DEFAULTCAPACITY_EMPTY_ELEMENTDATA; } 有参构造 指定容量的有参构造方法 public ArrayList(int initialCapacity) { // 校验参数是否大于0,大于0时创建指定大小数组,原创 2021-10-20 15:56:08 · 73 阅读 · 0 评论 -
ArrayList原理学习(一)
ArrayList原理学习(一) ArrayList集合内置属性 // 默认的数组大小 private static final int DEFAULT_CAPACITY = 10; // 用于空实例的共享空数组实例。 private static final Object[] EMPTY_ELEMENTDATA = {}; // 共享的空数组实例用于默认大小的空实例 private static final Object[] DEFAULTCAPACITY_EMPTY_ELEMENTDATA = {};原创 2021-10-20 11:44:14 · 158 阅读 · 0 评论 -
List数据读取注意
List数据读取注意** 当遍历List数据时,需要注意该List是否实现了RandomAccess接口,当实现该接口时使用随机遍历方法效率要高于顺序遍历方法。当未实现RandomAccess接口时,顺序遍历效率高于随机遍历方法。 // 判断是否实现RandomAccess接口 if (list instanceof RandomAccess){ // 随机访问 for (int i = 0; i < list.size(); i++) { System.out.println(list.get(i)原创 2021-10-19 17:03:27 · 452 阅读 · 1 评论