Share on Google+Share on Google+

Reads the character at buffer's current position.

Advertisement
In this tutorial you will see how to read the character at buffer's current position.

Reads the character at buffer's current position.

In this tutorial you will see how to read the character at buffer's current position. The get method actually get the value from current position and increment its position also. 

Code:

import java.nio.CharBuffer;

public class CharBufferDemo {
  public static void main(String[] args) {
    char[] chr = new char[] { 'a''b''c''d''e' };
    CharBuffer charbuffer1 = CharBuffer.allocate(10);
    charbuffer1.put(chr);
    charbuffer1.rewind();
    for (int i = 0; i < charbuffer1.length(); i++)
      System.out.print(" " + charbuffer1.get());
  }
}

Output:

  a b c d e

Download this code

Advertisements

Posted on: July 27, 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.