Easy way to concatenate two byte arrays

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

    Here's a nice solution using Guava's com.google.common.primitives.Bytes:

    byte[] c = Bytes.concat(a, b);
    

    The great thing about this method is that it has a varargs signature:

    public static byte[] concat(byte[]... arrays)
    

    which means that you can concatenate an arbitrary number of arrays in a single method call.

提交回复
热议问题