java-数组连接的几种方式
多个数组进行拼接,
1, 使用java自己的 System#arrayCopy()
byte[] message = new byte[heads.length + result.length + bodies.length]; System.arraycopy(heads, 0, message, 0, heads.length); System.arraycopy(result, 0, message, heads.length, result.length); System.arraycopy(bodies, 0, message, heads.length + result.length, bodies.length);
第二种方式, 使用netty的byteBuf
ByteBuf buffer = Unpooled.buffer(); buffer.writeBytes(heads); buffer.writeBytes(result); buffer.writeBytes(bodies); byte[] message1 = new byte[buffer.readableBytes()]; buffer.readBytes(message1);
未完待续...