ArrayList.add(int index, E element)
/** * ArrayList.add(int index, E element) */
public void add(int index, E element) {
rangeCheckForAdd(index);
ensureCapacityInternal(size + 1);
// 数组拷贝
System.arraycopy(elementData, index, elementData, index + 1,
size - index);
elementData[index] = element;
size++;
}
// System类的本地方法
public static native void arraycopy(Object src, int srcPos,
Object dest, int destPos,
int length);