Java Utililty Methods Array Concatenate

List of utility methods to do Array Concatenate

Description

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

Method

Object[]concatArrays(Object[] ar1, Object[] ar2)
concat Arrays
List<Object> thelist = new ArrayList<Object>();
for (Object o : ar1)
    thelist.add(o);
for (Object o : ar2)
    thelist.add(o);
return thelist.toArray();
short[]concatArrays(short[] arr1, short[] arr2)
concat Arrays
int len1 = arr1.length;
int len2 = arr2.length;
short[] retval = new short[len1 + len2];
System.arraycopy(arr1, 0, retval, 0, len1);
System.arraycopy(arr2, 0, retval, len1, len2);
return retval;
String[]concatArrays(String[] A, String[] B)
Concatenates two String arrays.
String[] C = new String[A.length + B.length];
System.arraycopy(A, 0, C, 0, A.length);
System.arraycopy(B, 0, C, A.length, B.length);
return C;
String[]concatArrays(String[] array, String[] arrayToBeConcat)
concat Arrays
String[] concatedArray = new String[array.length + arrayToBeConcat.length];
System.arraycopy(array, 0, concatedArray, 0, array.length);
System.arraycopy(arrayToBeConcat, 0, concatedArray, array.length, arrayToBeConcat.length);
return concatedArray;
T[]concatArrays(T[] first, T[] second)
Concatenate two arrays and return the result.
if (first == null && second == null)
    return null;
if (first == null)
    return second;
if (second == null)
    return first;
T[] result = Arrays.copyOf(first, first.length + second.length);
System.arraycopy(second, 0, result, first.length, second.length);
...
T[]concatArrays(T[] first, T[] second)
Concatenate two arrays of the same type.
T[] result = Arrays.copyOf(first, first.length + second.length);
System.arraycopy(second, 0, result, first.length, second.length);
return result;
byte[]concatByteArrays(final byte[] array1, final byte[] array2)
Concatenate 2 arrays of bytes.
byte[] result = new byte[array1.length + array2.length];
System.arraycopy(array1, 0, result, 0, array1.length);
System.arraycopy(array2, 0, result, array1.length, array2.length);
return result;
T[]concatenate(@SuppressWarnings("unchecked") T[]... arrays)
This method copies all the Objects in all the given Object[]s into one large array in which the elements are ordered according to the order of the arrays given as arguments.
int new_length = 0;
for (T[] array : arrays)
    new_length += array.length;
@SuppressWarnings("unchecked")
T[] result = (T[]) new ArrayList<T>(new_length).toArray();
int counter = 0; 
for (int i = 0; i < arrays.length; i++)
    for (int j = 0; j < arrays[i].length; j++) {
...
byte[]concatenate(byte[] a, byte[] b)
concatenate
byte[] local_a = Arrays.copyOf(a, a.length);
byte[] local_b = Arrays.copyOf(b, b.length);
byte[] concatenated = new byte[local_a.length + local_b.length];
System.arraycopy(local_a, 0, concatenated, 0, local_a.length);
System.arraycopy(local_b, 0, concatenated, local_a.length, local_b.length);
return concatenated;
double[]concatenate(double[] p1, double[] p2)
concatenate
double[] ret = new double[p1.length + p2.length];
ArrayList<Double> lst = new ArrayList<>();
for (int i = 0; i < p1.length; i++) {
    lst.add(p1[i]);
for (int i = 0; i < p2.length; i++) {
    lst.add(p2[i]);
Double[] d = new Double[p1.length + p2.length];
d = lst.toArray(d);
for (int i = 0; i < d.length; i++) {
    ret[i] = d[i];
return ret;