Home Tutorial Java Corejava Nio Wraps a character array into a buffer

 
 

Wraps a character array into a buffer
Posted on: July 26, 2010 at 12:00 AM
In this tutorial you will see how to wraps a character array into a buffer.

Wraps a character array into a buffer

In this tutorial you will see how to wraps a character array into a buffer. The public static CharBuffer wrap(char[] array) method allow character array to wrap it into a buffer.

Code:

import java.nio.CharBuffer;

public class CharBufferDemo1 {
  public static void main(String[] args) {
    char[] ch = new char[] { 'a''b''c''d''e' };
    CharBuffer charbuffer1 = CharBuffer.wrap(ch);
    System.out.println(charbuffer1.get(1));
  }
}

Output:

  b

Download this code

Related Tags for Wraps a character array into a buffer:


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.