Use of equals() method of  FloatBuffer class in java.


 

Use of equals() method of  FloatBuffer class in java.

In this tutorial you will see use of equals() method of  FloatBuffer class in java.

In this tutorial you will see use of equals() method of  FloatBuffer class in java.

Use of equals() method of  FloatBuffer class in java.

 In this tutorial, we will check  float buffer is equal  to another buffer or not.

FloatBuffer API:

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

Return type Method Description
static FloatBuffer allocate(int capacity)  The allocate(..)method allocate a new byte buffer.
boolean equals(object obj) The equals() method tells this buffer is equals or not to another object. If another buffer is not float buffer method returns false.
abstract FloatBuffer put(float f) The put(..)method write a given float value at current position.

code

import java.nio.*;
import java.nio.FloatBuffer;
import java.nio.DoubleBuffer;
public class FloatEqualDemo {
  public static final int size = 256;
public static void main(String[] args){
    FloatBuffer floatBuf = FloatBuffer.allocate(size);
    FloatBuffer floatBuf1 = FloatBuffer.allocate(size);
    if (floatBuf.equals(floatBuf1)) {
      System.out.println("Equals");
    else {
      System.out.println("Not equals");
    }
    floatBuf.put(21.09f);
    floatBuf.put(24.3f);
    floatBuf1.put(34.54f);
    floatBuf1.put(76.78f);
    if (floatBuf.equals(floatBuf1)) {
      System.out.println("Equals");
    else {
      System.out.println("Not equals");
    }
  DoubleBuffer doubleBuf = DoubleBuffer.allocate(size);
    if (floatBuf.equals(doubleBuf)) {
      System.out.println("Equals");
    else {
      System.out.println("Not equals");
    }
  }
}

Output

C:\>java FloatEqualDemo
Equals
Equals
Not equals

Download this code

Ads