Reputation: 4561
Suppose I have a byte array with 65 indices, and I want to fill the first 62 indices (or bytes) with data since index 63-65 are reserved. How can I move a byte array to the first 62 indices of the byte array?
String message = "Hello to the client. This is the message that you will receive"; //62 bytes message
byte[] b = message.getBytes();
byte[] sendData = new byte[65];
//how can I transfer byte[] b to 0-62?
Upvotes: 0
Views: 366
Reputation: 73460
Loop through the 62 indeces (0-61 btw) and copy the cells.
for (int i = 0; i < b.length; i++) {
sendData[i] = b[i];
}
Upvotes: 1
Reputation: 7074
I'm not entirely sure what you're getting at, but I think the Arrays.copy
method will help you. With this method, you can copy certain parts of an array to other arrays, saving the sections you're concerned about.
Upvotes: 0