/** * Inserts the specified element at the specified position in this list. * Shifts the element currently at that position (if any) and any subsequent * elements to the right (adds one to their indices). * * @param index the index at which to insert the element * @param element the value to insert */ public void add(int index, int element) { checkRangeIncludingEndpoint(index); ensureCapacity(size + 1); int numtomove = size - index; System.arraycopy(array, index, array, index + 1, numtomove); array[index] = element; size++; }
/** * Inserts the specified element at the specified position in this list. * Shifts the element currently at that position (if any) and any subsequent * elements to the right (adds one to their indices). * * @param index the index at which to insert the element * @param element the value to insert */ public void add(int index, int element) { checkRangeIncludingEndpoint(index); ensureCapacity(size + 1); int numtomove = size - index; System.arraycopy(array, index, array, index + 1, numtomove); array[index] = element; size++; }