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

T[]concatAll(T[] first, T[]... rest)
concat All
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[]concatAllArrays(byte[] data1, byte[]... remaining)
concat All Arrays
int bufLength = data1.length;
for (byte[] arr : remaining) {
    if (arr.length == 0) {
        return data1;
    bufLength += arr.length;
int offset = data1.length;
...
byte[]concatArray(byte data1[], byte data2[])
concat Array
byte temp[] = new byte[data1.length + data2.length];
System.arraycopy(data1, 0, temp, 0, data1.length);
System.arraycopy(data2, 0, temp, data1.length, data2.length);
return (temp);
byte[]concatArray(byte[] old1, byte[] old2)
concat Array
byte[] newArray = new byte[old1.length + old2.length];
System.arraycopy(old1, 0, newArray, 0, old1.length);
System.arraycopy(old2, 0, newArray, old1.length, old2.length);
return newArray;
StringconcatArray(int[] src, String separator)
concat Array
if (src.length == 0) {
    return null;
if (src.length <= 1) {
    return String.valueOf(src[0]);
StringBuilder builder = new StringBuilder();
builder.append(src[0]);
...
StringconcatArray(Object... objects)
Turns all passed objects to strings using their toString() method and concatenates the results.
return concatArray(new StringBuilder(), objects).toString();
Object[]concatArray(Object[] arr1, Object newValue)
concat Array
Object[] arr2 = new Object[1];
arr2[0] = newValue;
return concatArray(arr1, arr2);
StringconcatArray(String string, String[] words)
concat Array
StringBuilder concat = new StringBuilder();
for (int i = 0; i < words.length; i++) {
    concat.append(words[i] + " ");
return concat.toString().trim();
StringconcatArray(String[] array, int start)
concat Array
String str = array[start];
for (int i = start + 1; i < array.length; i++) {
    str = str + " " + array[i];
return str;
StringconcatArray(String[] array, int start, String def)
concat Array
if (array.length <= start)
    return def;
if (array.length <= start + 1)
    return array[start];
String ret = array[start];
for (int i = start + 1; i < array.length; i++) {
    ret += " " + array[i];
return ret;