In this tutorial we will see how to create a buffer and put content into it and compare byte data of one buffer with another.
import java.nio.CharBuffer; public class CharBufferDemo { public static void main(String[] args) { CharBuffer charbuffer1 = CharBuffer.allocate(6); CharBuffer charbuffer2 = CharBuffer.allocate(6); charbuffer1.put('B').put('U').put('F').put('F').put('E').put('R'); charbuffer2.put('B').put('U').put('F').put('F').put('E').put('R'); charbuffer1.rewind(); charbuffer2.rewind(); if (charbuffer1.limit(5).equals(charbuffer2.limit(5))) System.out.println("True"); else System.out.println("False"); }
Download this code
Related Tags for Compare two buffer's content: