Here you can find the source of merge(List
public static byte[] merge(List<byte[]> bs)
//package com.java2s; //License from project: Apache License import java.util.List; public class Main { public static byte[] merge(List<byte[]> bs) { int len = 0; for (int i = 0; i < bs.size(); i++) { len += bs.get(i).length;/* w w w . j a va2 s .co m*/ } byte[] merged = new byte[len]; int x = 0; for (int i = 0; i < bs.size(); i++) { byte[] b = bs.get(i); int blen = b.length; // copy(byte[] src, int srcPos, byte[] dest, int destPos, int length) copy(b, 0, merged, x, blen); x += blen; } return merged; } public static byte[] merge(byte[]... bs) { int len = 0; for (int i = 0; i < bs.length; i++) { len += bs[i].length; } byte[] merged = new byte[len]; int x = 0; for (int i = 0; i < bs.length; i++) { byte[] b = bs[i]; int blen = b.length; // copy(byte[] src, int srcPos, byte[] dest, int destPos, int length) copy(b, 0, merged, x, blen); x += blen; } return merged; } /** * copy bytes from src to dest * * @param src * @param srcPos * @param dest * @param destPos * @param length */ public static void copy(byte[] src, int srcPos, byte[] dest, int destPos, int length) { System.arraycopy(src, srcPos, dest, destPos, length); } /** * copy bytes from src to dest * * @param src * @param dest * @param destPos */ public static void copy(byte[] src, byte[] dest, int destPos) { System.arraycopy(src, 0, dest, destPos, src.length); } /** * dest[destPos] = src; * * @param src * @param dest * @param destPos */ public static void copy(byte src, byte[] dest, int destPos) { dest[destPos] = src; } }