/** * Appends the specified element to the end of this list. */ public void add(int element) { ensureCapacity(size + 1); array[size++] = element; }
/** * Appends all of the elements in the specified array to the end of this list. */ public void addAll(int[] data) { int dataLen = data.length; if (dataLen == 0) { return; } int newcap = size + (int) (dataLen * 1.1) + 1; ensureCapacity(newcap); System.arraycopy(data, 0, array, size, dataLen); size += dataLen; }
/** * Appends all of the elements in the specified array at the specified position in this list. */ public void addAll(int index, int[] data) { int dataLen = data.length; if (dataLen == 0) { return; } int newcap = size + (int) (dataLen * 1.1) + 1; ensureCapacity(newcap); System.arraycopy(array, index, array, index + dataLen, size - index); System.arraycopy(data, 0, array, index, dataLen); size += dataLen; }
/** * 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++; }
/** * Appends the specified element to the end of this list. */ public void add(int element) { ensureCapacity(size + 1); array[size++] = element; }
/** * Appends all of the elements in the specified array to the end of this list. */ public void addAll(int[] data) { int dataLen = data.length; if (dataLen == 0) { return; } int newcap = size + (int) (dataLen * 1.1) + 1; ensureCapacity(newcap); System.arraycopy(data, 0, array, size, dataLen); size += dataLen; }
/** * Appends all of the elements in the specified array at the specified position in this list. */ public void addAll(int index, int[] data) { int dataLen = data.length; if (dataLen == 0) { return; } int newcap = size + (int) (dataLen * 1.1) + 1; ensureCapacity(newcap); System.arraycopy(array, index, array, index + dataLen, size - index); System.arraycopy(data, 0, array, index, dataLen); size += dataLen; }
/** * 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++; }