Share on Google+Share on Google+

Writes the given character into buffer at the given index.

Advertisement
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

Advertisements

Posted on: July 26, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.