How to concatinate byte array in java

What is the simple method two concatenate two byte arrays in Java ?
i use this function but CREATE an error…java.lang.ArrayIndexOutOfBoundsException: 16

public static byte[] concatinate(byte[] a, byte[] b) {
byte[] c = new byte[100];
for (int i = 0; i < (a.length + b.length); i++) {
if (i < a.length) {
 c[i] = a[i];
 } else {
 c[i] = b[i];
return c;

Source: java

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.