0

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.

3
  • 1
    Unclear what you're asking. Can you please give some examples? Commented Apr 30, 2018 at 9:00
  • 1
    Can you post some code for context? Commented Apr 30, 2018 at 9:00
  • 1
    what is your input + expected output? Commented Apr 30, 2018 at 9:03

1 Answer 1

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.