Home Tutorial Java Corejava Nio Use of equals() method of IntBuffer class in java.

 
 

Share on Google+Share on Google+
Use of equals() method of IntBuffer class in java.
Posted on: August 3, 2010 at 12:00 AM
Advertisement
In this tutorial you will see the use of equals() method of IntBuffer class in java.

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

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

IntBuffer API:

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

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

Code

import java.nio.*;
import java.nio.IntBuffer;
import java.nio.FloatBuffer;
public class EqualDemo {
  public static final int size = 512;
public static void main(String[] argvthrows Exception{
    IntBuffer intBuf = IntBuffer.allocate(size);
    FloatBuffer floatBuf = FloatBuffer.allocate(size);
    if (intBuf.equals(floatBuf)) {
      System.out.println("Equal");
    else {
      System.out.println("Not equal");
    }
    IntBuffer intBuf1 = IntBuffer.allocate(size);
    if (intBuf.equals(intBuf1)) {
      System.out.println("Equal");
    else {
      System.out.println("Not equal");
    }
    intBuf.put(9);
    intBuf.put(3);
    intBuf1.put(7);
    if (intBuf.equals(intBuf1)) {
      System.out.println("Equal");
    else {
      System.out.println("Not equal");
    }

  }
}

Output

C:\l>java EqualDemo
Not equal
Equal
Not equal

Download this code

Advertisement

Related Tags for Use of equals() method of IntBuffer class in java.:


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: August 3, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com