Java Array Concatenate concatArrays(byte[][] arrays)

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

Description

concat Arrays

License

Open Source License

Declaration

public static byte[] concatArrays(byte[][] arrays) 

Method Source Code

//package com.java2s;
/*/*from w w  w .  j av  a  2 s.co m*/
 * gMix open source project - https://svs.informatik.uni-hamburg.de/gmix/
 * Copyright (C) 2012  Karl-Peter Fuchs
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    public static byte[] concatArrays(byte[][] arrays) {

        byte[] result = concatArrays(arrays[0], arrays[1]);

        for (int i = 2; i < arrays.length; i++)
            result = concatArrays(result, arrays[i]);

        return result;

    }

    public static byte[] concatArrays(byte[] firstArray, byte[] secondArray) {

        byte[] result = new byte[firstArray.length + secondArray.length];

        System.arraycopy(firstArray, 0, result, 0, firstArray.length);

        System.arraycopy(secondArray, 0, result, firstArray.length, secondArray.length);

        return result;

    }

    public static double[] concatArrays(double[] firstArray, double[] secondArray) {

        double[] result = new double[firstArray.length + secondArray.length];

        System.arraycopy(firstArray, 0, result, 0, firstArray.length);

        System.arraycopy(secondArray, 0, result, firstArray.length, secondArray.length);

        return result;

    }
}

Related

  1. concatArray(T[] first, T[]... rest)
  2. concatArrays(byte[] a, byte[] b)
  3. concatArrays(byte[]... arrays)
  4. concatArrays(byte[]... arrays)
  5. concatArrays(byte[]... byaArrays)
  6. concatArrays(double[] d1, double[] d2)
  7. concatArrays(final byte[] arr1, final byte[] arr2)
  8. concatArrays(final char[] first, final char[]... rest)
  9. concatArrays(Object[] ar1, Object[] ar2)