Home Tutorial Java Corejava Nio Place array of bytes in buffer

 
 

Place array of bytes in buffer
Posted on: July 26, 2010 at 12:00 AM
Advertisement
In this tutorial you will see how to place array of bytes in buffer.

Place array of bytes in buffer

In this tutorial you will see how to place array of bytes in buffer. The put method of CharBuffer class transfers the entire content of the given source character array into a buffer.

Code:

import java.nio.CharBuffer;

public class CharBufferDemo {
  public static void main(String[] args) {
    char[] c = new char[] { 'a''b''c''d''e' };
    CharBuffer charbuffer1 = CharBuffer.allocate(5);
    charbuffer1.put(c);
    System.out.println(charbuffer1.get(2));
  }
}

Output:

  c

Download this code

Advertisement

Related Tags for Place array of bytes in buffer:


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.

Posted on: July 26, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com