Java tutorial
//package com.java2s; public class Main { /** * Concatenate two byte arrays. No null checks are performed. * * @param x1 the first array * @param x2 the second array * @return (x2||x1) (little-endian order, i.e. x1 is at lower memory * addresses) */ public static byte[] concatenate(byte[] x1, byte[] x2) { byte[] result = new byte[x1.length + x2.length]; System.arraycopy(x1, 0, result, 0, x1.length); System.arraycopy(x2, 0, result, x1.length, x2.length); return result; } /** * Convert a 2-dimensional byte array into a 1-dimensional byte array by * concatenating all entries. * * @param array a 2-dimensional byte array * @return the concatenated input array */ public static byte[] concatenate(byte[][] array) { int rowLength = array[0].length; byte[] result = new byte[array.length * rowLength]; int index = 0; for (int i = 0; i < array.length; i++) { System.arraycopy(array[i], 0, result, index, rowLength); index += rowLength; } return result; } }