Home Tutorial Java Corejava Nio Compare two buffer's content

 
 

Compare two buffer's content
Posted on: July 24, 2010 at 12:00 AM
Advertisement
In this tutorial you will learn about how to compare two buffer's content

Compare two buffer's content

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.

Code:

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");
  }
 

Output:

  True

Download this code

Advertisement

Related Tags for Compare two buffer's content:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 24, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com