Skip to content

Instantly share code, notes, and snippets.

@massimilianochiodi
Created April 15, 2022 08:36
Show Gist options
  • Save massimilianochiodi/620dda329311b7fccd2d67f3677cb5cd to your computer and use it in GitHub Desktop.
Save massimilianochiodi/620dda329311b7fccd2d67f3677cb5cd to your computer and use it in GitHub Desktop.
Concatenate X byte array onto one
byte[] concat(byte[]...arrays)
{
// Determine the length of the result array
int totalLength = 0;
for (byte[] array : arrays) {
totalLength += array.length;
}
// create the result array
byte[] result = new byte[totalLength];
// copy the source arrays into the result array
int currentIndex = 0;
for (byte[] array : arrays) {
System.arraycopy(array, 0, result, currentIndex, array.length);
currentIndex += array.length;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment