Easy way to concatenate two byte arrays

前端 未结 12 1634
一个人的身影
一个人的身影 2020-12-02 04:25

What is the easy way to concatenate two byte arrays?

Say,

byte a[];
byte b[];

How do I concatenate two byte

12条回答
  •  北海茫月
    2020-12-02 05:21

    Most straightforward:

    byte[] c = new byte[a.length + b.length];
    System.arraycopy(a, 0, c, 0, a.length);
    System.arraycopy(b, 0, c, a.length, b.length);
    

提交回复
热议问题