From c08571c4740fd282b2680e23e31731f7baea4e45 Mon Sep 17 00:00:00 2001 From: bandx <1125234354@qq.com> Date: Fri, 25 Oct 2019 11:11:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0ArrayList=E6=89=A9=E5=AE=B9?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/collections/ArrayList.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/collections/ArrayList.md b/docs/collections/ArrayList.md index 11bb2ae1..eaa58b47 100644 --- a/docs/collections/ArrayList.md +++ b/docs/collections/ArrayList.md @@ -41,6 +41,8 @@ private void grow(int minCapacity) { // overflow-conscious code int oldCapacity = elementData.length; + // 配置ArrayList的新容量,其中oldCapacity >> 1为右移运算,相当于oldCapacity除以2,不直接使用oldCapacity/2是因为在计算机中,位移运算比除法运算的运行效率更高 + // ArrayList扩容之后是扩容之前的容量的1.5倍 int newCapacity = oldCapacity + (oldCapacity >> 1); if (newCapacity - minCapacity < 0) newCapacity = minCapacity;