集合List添加集合,复制内容的方法
第一种:AddAll(): ArrayList 的AddAll()方法如下: public boolean addAll(Collection c) { Object[] a = c.toArray(); int numNew = a.length; ensureCapacityInternal(size + numNew); // Increments modCount System.arraycopy(a, 0, elementData, size, numNew); //核心代码 size += numNew; return numNew != 0; } 第二种:ArrayList(List A) public ArrayList(Collection c) { elementData = https://www.it610.com/article/c.toArray(); if ((size = elementData.length) != 0) { // c.toArray might (incorrectly) not return Object[] (see 6260652) if (elementData.getClass() != Object[].class) elementData = https://www.it610.com/article/Arrays.copyOf(elementData, size, Object[].class); //核心代码 } else { // replace with empty array. this.elementData = https://www.it610.com/article/EMPTY_ELEMENTDATA; } }
推荐阅读
- angular4|angular4 官网英雄指南02
- 数据库的日常操作|【Redis底层解析】整数集合
- 问题集合2
- 每日一考-9.11
- Java排序之集合排序
- 论文(DeepAR: Probabilistic Forecasting with Autoregressive Recurrent Networks)
- iOS笔记之使用贝塞尔曲线给View/Layer添加圆角
- R语言在散点图中添加lm线性回归公式的问题
- 框架大集合|【MyBatis详解】——动态SQL解析与执行原理
- 92.|92. Reverse Linked List II