/**
* @author lautturi.com
* Java example: how to combine two byte array in java
*/
import java.util.*;
public class Lautturi {
public static void main(String[] args) {
byte[] bytes1 = {104, 101, 108, 108, 111, 32};
byte[] bytes2 = {108, 97, 117, 116, 116, 117, 114, 105, 32, 106, 97, 118, 97, 33};
byte[] combined = new byte[bytes1.length + bytes2.length];
System.arraycopy(bytes1,0,combined,0 ,bytes1.length);
System.arraycopy(bytes2,0,combined,bytes1.length,bytes2.length);
System.out.println(Arrays.toString(combined));
}
}
output:
[104, 101, 108, 108, 111, 32, 108, 97, 117, 116, 116, 117, 114, 105, 32, 106, 97, 118, 97, 33]