在java中连接字节数组和int值

时间:2018-04-30 08:59:00

标签: java int concatenation byte

有没有办法在java中连接字节数组和int值。任何帮助表示赞赏。我所能找到的只是连接2个阵列。

int res = somefunction(byte [] buf,..); 现在我想连接buf和res。 如果需要,我可以使用String []而不是byte []。

1 个答案:

答案 0 :(得分:1)

byte[] buf = ...;
int res = somefunction(buf); 
byte[] buf2 = new byte[buf.length + 1];
System.arraycopy(buf, 0, buf2, 0, buf.length);
buf2[buf.length] = (byte)res;
buf = buf2;