Java Byte Array Combine combineArrays(byte[]... a)

Here you can find the source of combineArrays(byte[]... a)

Description

Combines multiple byte arrays into a single, longer byte array.

License

Apache License

Parameter

Parameter Description
a - The byte arrays to combine.

Return

The combined byte array.

Declaration

public static byte[] combineArrays(byte[]... a) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from   www  .  ja  v a2 s  .  com*/
     * Combines multiple byte arrays into a single, longer byte array. Each byte array is appended to the end of the previous byte
     * array. The arrays do not need to be the same length. An example: [1, 2, 3] and [4, 5] and [6, 7, 8, 9] would return the byte
     * array of [1, 2, 3, 4, 5, 6, 7, 8, 9].
     * @param a - The byte arrays to combine.
     * @return The combined byte array.
     */
    public static byte[] combineArrays(byte[]... a) {
        int massLength = 0;
        for (byte[] b : a)
            massLength += b.length;
        byte[] c = new byte[massLength];
        byte[] d;
        int index = 0;
        for (int i = 0; i < a.length; i++) {
            d = a[i];
            for (int j = 0; j < d.length; j++)
                c[j + index] = d[j];
            index += d.length;
        }
        return c;
    }
}

Related

  1. combine(byte[] one, byte[] two, byte[] three, byte[] four)
  2. combine(byte[] one, byte[] two, byte[] three, byte[] four)
  3. combine(byte[]... bytes)
  4. combine(byte[][] arr)
  5. combine(final byte[] array1, final byte[] array2)
  6. combineInsertB2sizeAsByte(byte[] b1, byte[] b2)