Writes the given character into buffer at the given index.


 

Writes the given character into buffer at the given index.

In this tutorial you will see how to write the given character into buffer at the given index.

In this tutorial you will see how to write the given character into buffer at the given index.

Writes the given character into buffer at the given index.

In this tutorial you will see how to write the given character into buffer at the given index. The put (int index, char c) allow to write a character at particular index. It also allow to overwrite the content of the buffer which can be seen in this example.

Code:

import java.nio.CharBuffer;

public class CharBufferDemo {
  public static void main(String[] argvthrows Exception {
    CharBuffer buffer = CharBuffer.allocate(8);
    buffer.put('a').put('b').put('c');
    buffer.put(1'x');
    buffer.put(3'd').put(4'e');
    System.out.println(buffer.get(1));
  }
}

Output:

  x

Download this code

Ads