Easy way to concatenate two byte arrays

前端 未结 12 1629
一个人的身影
一个人的身影 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:24

    If you prefer ByteBuffer like @kalefranz, there is always the posibility to concatenate two byte[] (or even more) in one line, like this:

    byte[] c = ByteBuffer.allocate(a.length+b.length).put(a).put(b).array();
    

提交回复
热议问题