Home Tutorial Java Corejava Nio Compare two double type buffer's content

 
 

Compare two double type buffer's content
Posted on: July 28, 2010 at 12:00 AM
In this tutorial we will see how to compare two double type buffer's content

Compare two double buffer's content

In this tutorial we will see how to create a double buffer and put content into it and then compare double value of one buffer with another.

Code:

import java.nio.DoubleBuffer;

public class DoubleBufferDemo {
  public static void main(String[] args) {
    DoubleBuffer doublebuffer1 = DoubleBuffer.allocate(6);
    DoubleBuffer doublebuffer2 = DoubleBuffer.allocate(6);
    doublebuffer1.put(1.00).
put
(2.123).put(3.154).put(30.544).put(45.545)
        .put(844.4554);
    doublebuffer2.put(2.32).put(7434.433).put(323.3434).put(34324.545).put(
        3434.54).put(56424.343);
    doublebuffer1.rewind();
    doublebuffer2.rewind();
    if (doublebuffer1.limit(5).equals(doublebuffer2.limit(5)))
      System.out.println("True");
    else
      System.out.println("False");
  }
}

Output:

  False

Download this code

Related Tags for Compare two double type buffer's content:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.