Created
April 15, 2022 08:36
-
-
Save massimilianochiodi/620dda329311b7fccd2d67f3677cb5cd to your computer and use it in GitHub Desktop.
Concatenate X byte array onto one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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