Hello,
I just need some help in ByteBuffer's put(index, byte) method.
Basically I have a byte array which stores data and is put into a ByteBuffer. The problem I'm facing is I want to put extra data in the ByteBuffer in index 2 (The positioning is very important)
How would i go about this without overriding the previous data?
Just an example of what I mean:
byte[] d = new byte[10];
for(byte i = 0; i < 10; i++)
d[i] = i;
ByteBuffer buffer = ByteBuffer.allocate(10);
buffer.put(d);
buffer.put(2, (byte)100);
for(byte b : buffer.array())
System.out.print(b);
The output of that would be
0
1
100
3
4
5
6
7
8
9
Instead I want
0
1
2
100
3
4
5
6
7
8
9
So any help in achieving this is much appreciated :)