Java Array Merge merge(final byte[]... data)

Here you can find the source of merge(final byte[]... data)

Description

merge

License

Open Source License

Declaration

public static byte[] merge(final byte[]... data) 

Method Source Code

//package com.java2s;
// it under the terms of the GNU General Public License as published by

public class Main {
    public static byte[] merge(final byte[]... data) {
        int size = 0;
        for (final byte[] a : data)
            size += a.length;/* ww w  . jav  a2 s.c  om*/

        final byte[] r = new byte[size];

        for (final byte[] a : data)
            combine(r, a);

        return r;
    }

    public static byte[] combine(final byte[] array1, final byte[] array2) {
        if (array1 == null)
            return copy(array2);
        else if (array2 == null)
            return copy(array1);
        final byte[] joinedArray = new byte[array1.length + array2.length];
        System.arraycopy(array1, 0, joinedArray, 0, array1.length);
        System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
        return joinedArray;
    }

    public static byte[] copy(final byte[] array) {
        if (array == null)
            return null;
        return array.clone();
    }
}

Related

  1. merge(double[] a, int[] b, int p, int q, int r)
  2. merge(double[]... args)
  3. merge(E[] a1, E[] a2)
  4. merge(E[] arrayA, E[] arrayB)
  5. merge(final byte[] b1, final byte[] b2)
  6. merge(final String[] array1, final String[] array2)
  7. merge(final T[] array1, final T[] array2)
  8. merge(int[] a, int l, int m, int h)
  9. merge(int[] a, int[] b)