Introduce merge arrays function

This commit is contained in:
Roman Mandeleil 2015-02-25 19:13:24 +02:00
parent 97258a1838
commit e0cebbba86
1 changed files with 25 additions and 0 deletions

View File

@ -349,4 +349,29 @@ public class ByteUtil {
byte dataByte = data[posByte];
return Math.min(1, (dataByte & (1 << (posBit))));
}
/**
* @param arrays - arrays to merge
* @return - merged array
*/
public static byte[] merge(byte[]... arrays)
{
int arrCount = 0;
int count = 0;
for (byte[] array: arrays)
{
arrCount++;
count += array.length;
}
// Create new array and copy all array contents
byte[] mergedArray = new byte[count];
int start = 0;
for (byte[] array: arrays) {
System.arraycopy(array, 0, mergedArray, start, array.length);
start += array.length;
}
return mergedArray;
}
}