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 48e383c commit 08d705dCopy full SHA for 08d705d
java/source-code/jdk/collection/list-vector.md
@@ -0,0 +1,26 @@
1
+# Vector
2
+
3
+## 数组容量自增
4
5
+```java
6
+private void grow(int minCapacity) {
7
+ // overflow-conscious code
8
+ int oldCapacity = elementData.length;
9
+ // 默认容量翻倍
10
+ int newCapacity = oldCapacity + ((capacityIncrement > 0) ?
11
+ capacityIncrement : oldCapacity);
12
+ if (newCapacity - minCapacity < 0)
13
+ newCapacity = minCapacity;
14
+ if (newCapacity - MAX_ARRAY_SIZE > 0)
15
+ newCapacity = hugeCapacity(minCapacity);
16
+ elementData = Arrays.copyOf(elementData, newCapacity);
17
+}
18
+```
19
20
+和 `ArrayList` 的区别是默认增长策略直接翻倍,且是同步的
21
22
+## 最后
23
24
+fast-fail。线程安全。
25
26
+没啥好说的。
0 commit comments