In this tutorial you will see how to compare double buffer to another object.
In this tutorial you will see how to compare double 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.
import java.nio.DoubleBuffer; public class DoubleBufferDemo { public static void main(String[] args) { double[] dbl = new double[] { 121.323, 2323, 32353.4, 432.45, 453.756 }; DoubleBuffer buffer1 = DoubleBuffer.allocate(10); buffer1.put(dbl); double[] db2 = new double[] { 121.323, 2323, 32353.4, 432.45, 453.756 }; DoubleBuffer buffer2 = DoubleBuffer.allocate(10); buffer2.put(db2); System.out.println(buffer2.compareTo(buffer1)); double[] db3 = new double[] { 121.323, 2323, 32353.4, 432.45, 453.756, 43.6453 }; DoubleBuffer buffer3 = DoubleBuffer.allocate(10); buffer3.put(db3); System.out.println(buffer3.compareTo(buffer1)); double[] db4 = new double[] { 121.323, 2323, 32353.4, 432.45 }; DoubleBuffer buffer4 = DoubleBuffer.allocate(10); buffer4.put(db4); System.out.println(buffer4.compareTo(buffer1)); } } |
0 -1 1 |