Android Utililty Methods Array Add

List of utility methods to do Array Add

Description

The list of methods to do Array Add are organized into topic(s).

Method

Objectadd(Object array, int index, Object element, Class clss)
Underlying implementation of add(array, index, element) methods.
if (array == null) {
    if (index != 0) {
        throw new IndexOutOfBoundsException("Index: " + index
                + ", Length: 0");
    Object joinedArray = Array.newInstance(clss, 1);
    Array.set(joinedArray, 0, element);
    return joinedArray;
...
T[]add(T[] array, T element)

Copies the given array and adds the given element at the end of the new array.

The new array contains the same elements of the input array plus the given element in the last position.

Class<?> type;
if (array != null) {
    type = array.getClass();
} else if (element != null) {
    type = element.getClass();
} else {
    throw new IllegalArgumentException(
            "Arguments cannot both be null");
...
T[]add(T[] array, int index, T element)

Inserts the specified element at the specified position in the array.

Class<?> clss = null;
if (array != null) {
    clss = array.getClass().getComponentType();
} else if (element != null) {
    clss = element.getClass();
} else {
    throw new IllegalArgumentException(
            "Array and element cannot both be null");
...
boolean[]add(boolean[] array, boolean element)

Copies the given array and adds the given element at the end of the new array.

The new array contains the same elements of the input array plus the given element in the last position.

boolean[] newArray = (boolean[]) copyArrayGrow1(array, Boolean.TYPE);
newArray[newArray.length - 1] = element;
return newArray;
boolean[]add(boolean[] array, int index, boolean element)

Inserts the specified element at the specified position in the array.

return (boolean[]) add(array, index, Boolean.valueOf(element),
        Boolean.TYPE);
byte[]add(byte[] array, byte element)

Copies the given array and adds the given element at the end of the new array.

The new array contains the same elements of the input array plus the given element in the last position.

byte[] newArray = (byte[]) copyArrayGrow1(array, Byte.TYPE);
newArray[newArray.length - 1] = element;
return newArray;
byte[]add(byte[] array, int index, byte element)

Inserts the specified element at the specified position in the array.

return (byte[]) add(array, index, Byte.valueOf(element), Byte.TYPE);
char[]add(char[] array, char element)

Copies the given array and adds the given element at the end of the new array.

The new array contains the same elements of the input array plus the given element in the last position.

char[] newArray = (char[]) copyArrayGrow1(array, Character.TYPE);
newArray[newArray.length - 1] = element;
return newArray;
char[]add(char[] array, int index, char element)

Inserts the specified element at the specified position in the array.

return (char[]) add(array, index, Character.valueOf(element),
        Character.TYPE);
double[]add(double[] array, double element)

Copies the given array and adds the given element at the end of the new array.

The new array contains the same elements of the input array plus the given element in the last position.

double[] newArray = (double[]) copyArrayGrow1(array, Double.TYPE);
newArray[newArray.length - 1] = element;
return newArray;