We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7a7b6a4 commit db8807eCopy full SHA for db8807e
docs/java/collection/ArrayList-Grow.md
@@ -270,7 +270,6 @@ public class ArrayscopyOfTest {
270
10
271
```
272
273
-
274
### 3.3 两者联系和区别
275
276
**联系:**
@@ -281,8 +280,6 @@ public class ArrayscopyOfTest {
281
280
282
`arraycopy()` 需要目标数组,将原数组拷贝到你自己定义的数组里或者原数组,而且可以选择拷贝的起点和长度以及放入新数组中的位置 `copyOf()` 是系统自动在内部新建一个数组,并返回该数组。
283
284
285
286
## 四 `ensureCapacity`方法
287
288
ArrayList 源码中有一个 `ensureCapacity` 方法不知道大家注意到没有,这个方法 ArrayList 内部没有被调用过,所以很显然是提供给用户调用的,那么这个方法有什么作用呢?
@@ -341,7 +338,6 @@ public class EnsureCapacityTest {
341
338
342
339
使用ensureCapacity方法前:4637
343
340
使用ensureCapacity方法后:241
344
345
346
347
通过运行结果,我们可以很明显的看出向 ArrayList 添加大量元素之前最好先使用`ensureCapacity` 方法,以减少增量重新分配的次数
0 commit comments