/**
企業(yè)建站必須是能夠以充分展現(xiàn)企業(yè)形象為主要目的,是企業(yè)文化與產(chǎn)品對(duì)外擴(kuò)展宣傳的重要窗口,一個(gè)合格的網(wǎng)站不僅僅能為公司帶來(lái)巨大的互聯(lián)網(wǎng)上的收集和信息發(fā)布平臺(tái),成都創(chuàng)新互聯(lián)公司面向各種領(lǐng)域:封陽(yáng)臺(tái)等成都網(wǎng)站設(shè)計(jì)、網(wǎng)絡(luò)營(yíng)銷推廣解決方案、網(wǎng)站設(shè)計(jì)等建站排名服務(wù)。
*/
private static final Object[] DEFAULTCAPACITY_EMPTY_ELEMENTDATA = {};
/**
@serial
*/
private int size;
//最大數(shù)組大小
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
//默認(rèn)實(shí)例為一個(gè)空數(shù)組
public ArrayList() {
this.elementData = DEFAULTCAPACITY_EMPTY_ELEMENTDATA;
}
//添加元素
public boolean add(E e) {
//確定容量
ensureCapacityInternal(size + 1); // Increments modCount!!
elementData[size++] = e;
return true;
}
private void ensureCapacityInternal(int minCapacity) {
ensureExplicitCapacity(calculateCapacity(elementData, minCapacity));
}
private void ensureExplicitCapacity(int minCapacity) {
modCount++;
// overflow-conscious code
//超過(guò)擴(kuò)容
if (minCapacity - elementData.length > 0)
grow(minCapacity);
}
private void grow(int minCapacity) {
// overflow-conscious code
int oldCapacity = elementData.length;
//擴(kuò)容方式 舊容量+舊容量右移一位
int newCapacity = oldCapacity + (oldCapacity >> 1);
if (newCapacity - minCapacity < 0)
newCapacity = minCapacity;
if (newCapacity - MAX_ARRAY_SIZE > 0)
newCapacity = hugeCapacity(minCapacity);
// minCapacity is usually close to size, so this is a win:
elementData = Arrays.copyOf(elementData, newCapacity);
}
//循環(huán)清除
public void clear() {
modCount++;
// clear to let GC do its work
for (int i = 0; i < size; i++)
elementData[i] = null;
size = 0;
}
//刪除 --很巧妙的刪除
public E remove(int index) {
rangeCheck(index);
modCount++;
E oldValue = elementData(index);
//獲得需要移動(dòng)的位數(shù)
int numMoved = size - index - 1;
if (numMoved > 0)
//進(jìn)行復(fù)制,最后一位會(huì)保留下來(lái)
System.arraycopy(elementData, index+1, elementData, index,
numMoved);
//數(shù)組大小減少一位,最后一位賦值為空
elementData[--size] = null; // clear to let GC do its work
return oldValue;
}