Java Byte Array Add addByteArrays(byte[]... arrays)

Here you can find the source of addByteArrays(byte[]... arrays)

Description

Returns a byte array containing the first supplied byte array, followed by the second, followed by the third, and so on...

License

Open Source License

Parameter

Parameter Description
arrays The byte arrays to concatenate

Return

The byte array which is all the supplied byte arrays concatenated in order

Declaration

public static byte[] addByteArrays(byte[]... arrays) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from  w ww  .j  av  a 2 s  .  c  om*/
     * Returns a byte array containing the first supplied byte array, followed by the second, followed
     * by the third, and so on...
     *
     * @param arrays The byte arrays to concatenate
     * @return The byte array which is all the supplied byte arrays concatenated in order
     */
    public static byte[] addByteArrays(byte[]... arrays) {
        int length = 0;
        for (byte[] ba : arrays) {
            length += ba.length;
        }

        byte[] retArray = new byte[length];
        int pos = 0;

        for (byte[] ba : arrays) {
            System.arraycopy(ba, 0, retArray, pos, ba.length);
            pos += ba.length;
        }

        return retArray;
    }
}

Related

  1. addByteArrays(byte[] array1, byte[] array2)
  2. addBytes(byte[] array, byte[] value)
  3. addBytes(byte[] initBytes, byte[] addBytes)
  4. addBytes(byte[][] src)
  5. appendByte(byte[] bytes, byte b)