Java CharBuffer store two bytes from ByteBuffer

Description

Java CharBuffer store two bytes from ByteBuffer

import java.nio.ByteBuffer;
import java.nio.CharBuffer;

public class Main {

   public static void main(String[] args) {
      char[] data = "demo2s.com".toCharArray();
      ByteBuffer bb = ByteBuffer.allocate(data.length * 2);

      CharBuffer cb = bb.asCharBuffer();
      cb.put(data);// w w  w  .  j  av a2 s . c o  m

      cb.rewind();
      System.out.println(cb);
   }

}



PreviousNext

Related