M.Dev
M.Dev

Reputation: 63

Concatenate byte array and int value in java

Is there a way to concatenate byte array and int value in java. Any help is appreciated. All I could find was concatenating 2 arrays.

int res=somefunction(byte[] buf,..); now i want to concatenate the buf and the res. I can use String[] instead of byte[] if needed.

Upvotes: 0

Views: 171

Answers (1)

guleryuz
guleryuz

Reputation: 2734

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;

Upvotes: 1

Related Questions