Share on Google+Share on Google+

Wraps a character array into a buffer

Advertisement
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

Advertisements

Advertisement

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.