Java CharBuffer store String

Description

Java CharBuffer store String

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

public class Main {
  public static void main(String[] argv) throws Exception {
    ByteBuffer buf = ByteBuffer.allocate(100);

    CharBuffer cbuf = buf.asCharBuffer();

    cbuf.put("demo2s.com");

    cbuf.flip();//from  ww w  . j a  v  a  2  s  .c o  m
    String s = cbuf.toString(); // a string
    
    System.out.println(s);
  }
}



PreviousNext

Related