import java.nio.*; import java.nio.ByteBuffer; import java.nio.CharBuffer; public class ByteBufferEqual{ public static final int size = 256; public static void main(String[] argv) throws Exception { byte[] bytes = new byte[size]; ByteBuffer bytebuf1 = ByteBuffer.wrap(bytes); ByteBuffer bytebuf = ByteBuffer.allocate(size); if (bytebuf1.equals(bytebuf)) { System.out.println("Equals"); } else { System.out.println("Not equals"); } bytebuf1.putInt(12); bytebuf.putChar('e'); if (bytebuf1.equals(bytebuf)) { System.out.println("Equals"); } else { System.out.println("Not equals"); } CharBuffer charbuf = CharBuffer.allocate(size); if (bytebuf1.equals(charbuf)) { System.out.println("Equals"); } else { System.out.println("Not equals"); } } }