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

StringconcatArray(String[] array, String glue)
concat Array
StringBuilder sb = new StringBuilder();
for (String s : array) {
    sb.append(s);
    sb.append(glue);
return sb.toString().substring(0, sb.toString().lastIndexOf(glue));
T[]concatArray(T[] first, T[]... rest)
concat Array
int totalLength = first.length;
for (T[] array : rest) {
    totalLength += array.length;
T[] result = Arrays.copyOf(first, totalLength);
int offset = first.length;
for (T[] array : rest) {
    System.arraycopy(array, 0, result, offset, array.length);
...
byte[]concatArrays(byte[] a, byte[] b)
concat Arrays
if (a == null || b == null) {
    throw new IllegalArgumentException(ERROR_NULL_ARRAYS);
byte[] concat = new byte[a.length + b.length];
for (int i = 0; i < concat.length; i++) {
    concat[i] = i < a.length ? a[i] : b[i - a.length];
return concat;
...
byte[]concatArrays(byte[]... arrays)
Takes a variable amount of byte arrays as input and returns a merged byte array by concatenating the input in the order of the parameterlist.
int length = 0;
for (byte[] arr : arrays)
    length += arr.length;
byte[] merged = new byte[length];
int offset = 0;
for (byte[] arr : arrays) {
    System.arraycopy(arr, 0, merged, offset, arr.length);
    offset += arr.length;
...
byte[]concatArrays(byte[]... arrays)
Concatenates the given arrays in order of their occurence
int size = 0;
for (byte[] cur : arrays) {
    if (cur == null)
        continue;
    size = size + cur.length;
byte[] out = new byte[size];
int curPos = 0;
...
byte[]concatArrays(byte[]... byaArrays)
Concatenate several byte arrays
int nLen = 0;
for (byte[] byaArr : byaArrays) {
    nLen += byaArr.length;
byte[] byaRet = new byte[nLen];
int nPos = 0;
for (byte[] byaArr : byaArrays) {
    System.arraycopy(byaArr, 0, byaRet, nPos, byaArr.length);
...
byte[]concatArrays(byte[][] arrays)
concat Arrays
byte[] result = concatArrays(arrays[0], arrays[1]);
for (int i = 2; i < arrays.length; i++)
    result = concatArrays(result, arrays[i]);
return result;
double[]concatArrays(double[] d1, double[] d2)
concat Arrays
double[] result = new double[d1.length + d2.length];
for (int i = 0; i < d1.length; i++)
    result[i] = d1[i];
for (int i = 0; i < d2.length; i++)
    result[i + d1.length] = d2[i];
return result;
byte[]concatArrays(final byte[] arr1, final byte[] arr2)
Concatenate arrays.
final byte result[] = new byte[arr1.length + arr2.length];
System.arraycopy(arr1, 0, result, 0, arr1.length);
System.arraycopy(arr2, 0, result, arr1.length, arr2.length);
return result;
char[]concatArrays(final char[] first, final char[]... rest)
Concatenates multiple character arrays together.
int totalLength = first.length;
for (char[] array : rest) {
    if (array != null) {
        totalLength += array.length;
final char[] result = Arrays.copyOf(first, totalLength);
int offset = first.length;
...