import java.nio.*; import java.nio.ByteBuffer; public class PutAtIndex { public static final int capacity = 9; public static void main(String[] args) { try { ByteBuffer byteBuf = ByteBuffer.allocate(capacity); int i = 3; System.out.println("Write value at index " + i); byteBuf.putChar(i, 'B'); byteBuf.rewind(); System.out.print("\nRead value from index " + i + " : "); while (byteBuf.hasRemaining()) { System.out.print((char) byteBuf.get()); } } catch (Exception e) { System.out.println(e); } } }