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);

 

未完待续... 

posted @ 2018-06-06 11:42  bronk  阅读(11479)  评论(0编辑  收藏  举报