Home Tutorial Java Corejava Nio Compare a double type buffer to another object

 
 

Share on Google+Share on Google+
Compare a double type buffer to another object
Posted on: July 28, 2010 at 12:00 AM
Advertisement
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

Advertisement

Related Tags for Compare a double type buffer to another object:


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 28, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com