ArrayList的扩容机制
这里结合源码分析一下ArrayList的扩容机制,基于JDK8 参考文章,点击这里 首先分析ArrayList源码中的属性 /** * 默认初始容量大小 */ private static final int DEFAULT_CAPACITY = 10; private static final Object[] DEFAULTCAPACITY_EMPTY_ELEMENTDATA = {}; /** * The array buffer into which the elements of the ArrayList are stored. * The capacity of the ArrayList is the length of this array buffer. * 【 Any empty ArrayList with elementData == DEFAULTCAPACITY_EMPTY_ELEMENTDATA * will be expanded to DEFAULT_CAPACITY when the first element is added.】 */ transient Object[] elementData; // non-private to simplify nested class access /** *默认构造函数