Home Tutorial Java Corejava Nio Reads the character at buffer's current position.

 
 

Reads the character at buffer's current position.
Posted on: July 27, 2010 at 12:00 AM
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

Related Tags for Reads the character at buffer's current position.:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.