List集合底層實現
阿新 • • 發佈:2019-01-03
1. public ArrayList() {
2. this(10);
3. }
4.
5. public ArrayList(int initialCapacity) {
6. super();
7. if (initialCapacity < 0)
8. throw new IllegalArgumentException("Illegal Capacity: "+ initialCapacity);
9. this.elementData = new Object[initialCapacity];
10. }
11.
12. public ArrayList(Collection<? extends E> c) {
13. elementData = c.toArray();
14. size = elementData.length;
15. // c.toArray might (incorrectly) not return Object[] (see 6260652)
16. if (elementData.getClass() != Object[].class)
17. elementData = Arrays.copyOf(elementData, size, Object[].class);
18. }