Compare a double type buffer to another object

In this tutorial you will see how to compare double buffer to another object.

 
 

Share on Google+Share on Google+

Compare a double type buffer to another object

Ads

In this tutorial you will see how to compare double buffer to another object.

Compare a double type buffer to another object

In this tutorial you will see how to compare double buffer to another object. The compareTo method of DoubleBuffer class allow to compare buffer with another. This method returns 0, 1 or -1 which means it is equal, less and greater than the comparing buffer.

Code:

import java.nio.DoubleBuffer;

public class DoubleBufferDemo {
  public static void main(String[] args) {
    double[] dbl = new double[] { 121.323232332353.4432.45453.756 };
    DoubleBuffer buffer1 = DoubleBuffer.allocate(10);
    buffer1.put(dbl);

    double[] db2 = new double[] { 121.323232332353.4432.45453.756 };
    DoubleBuffer buffer2 = DoubleBuffer.allocate(10);
    buffer2.put(db2);
    System.out.println(buffer2.compareTo(buffer1));

    double[] db3 = new double[] { 121.323232332353.4432.45453.756,
        43.6453 };
    DoubleBuffer buffer3 = DoubleBuffer.allocate(10);
    buffer3.put(db3);
    System.out.println(buffer3.compareTo(buffer1));

    double[] db4 = new double[] { 121.323232332353.4432.45 };
    DoubleBuffer buffer4 = DoubleBuffer.allocate(10);
    buffer4.put(db4);
    System.out.println(buffer4.compareTo(buffer1));
  }
}

Output:

  0
  -1
  1

Download this code

Advertisements

Ads

Posted on: July 28, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles