Java ByteBuffer convert to CharBuffer with half size
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);/*from ww w. j av a2 s . c o m*/ cb.rewind(); System.out.println(cb); } }