Java CharBuffer compare with ByteBuffer for byte content
import java.nio.ByteBuffer; import java.nio.CharBuffer; public class Main { public static void main(String[] args) { ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, 'a' }); bb.rewind();//w w w .ja v a 2s. c o m System.out.println("Byte Buffer"); while (bb.hasRemaining()) System.out.println(bb.position() + " -> " + bb.get()); CharBuffer cb = ((ByteBuffer) bb.rewind()).asCharBuffer(); System.out.println("Char Buffer"); while (cb.hasRemaining()) System.out.println(cb.position() + " -> " + cb.get()); } }