Another possibility is using java.nio.ByteBuffer
.
Something like
ByteBuffer bb = ByteBuffer.allocate(a.length + b.length + c.length);
bb.put(a);
bb.put(b);
bb.put(c);
byte[] result = bb.array();
// or using method chaining:
byte[] result = ByteBuffer
.allocate(a.length + b.length + c.length)
.put(a).put(b).put(c)
.array();
Note that the array must be appropriately sized to start with, so the allocation line is required (as array()
simply returns the backing array, without taking the offset, position or limit into account).