Home Tutorial Java Corejava Nio Compare a float buffer with another float buffer.

 
 

Share on Google+Share on Google+
Compare a float buffer with another float buffer.
Posted on: July 30, 2010 at 12:00 AM
Advertisement
In this tutorial you will see how to compare a float buffer with another float buffer.

Compare a float buffer with another float buffer.

 In this tutorial, we will see how to compare a float buffer with another float buffer.

FloatBuffer API:

The java.nio.FloatBuffer class extends java.nio.Buffer class. It provides the following methods:

Return type Method Description
staticFloatBuffer allocate(int capacity)  The allocate(..)method allocate a new float buffer.
int compareTo(FloatBuffer buffer) The compareTo() method returns 0, -1 or 1. It means this buffer is equal, less and greater than to another buffer.
abstract  FloatBuffer put(float f) The put(..) method write a given float value at the current position.

code

import java.nio.*;
import java.nio.FloatBuffer;

public class FloatCompareDemo {
public static void main(String[] args){
    FloatBuffer floatBuf = FloatBuffer.allocate(256);
    floatBuf.put(4.2f);
    floatBuf.put(5.1f);
    floatBuf.put(6.4f);
    FloatBuffer floatBuf1 = FloatBuffer.allocate(256);
    floatBuf1.put(98.54f);
    floatBuf1.put(5.3f);
    int i=floatBuf.compareTo(floatBuf1);
    System.out.println(i);    
    FloatBuffer floatBuf2 = FloatBuffer.allocate(256);
    floatBuf2.put(76.45f);
    floatBuf2.put(98.32f);
    int i1=floatBuf2.compareTo(floatBuf1);
    System.out.println(i1);
    int i2=floatBuf2.compareTo(floatBuf);
    System.out.println(i2);
    }
  }

Output

C:\>java FloatCompareDemo
-1
0
1

Download this code

Advertisement

Related Tags for Compare a float buffer with another float buffer.:


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

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com