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

 
 

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

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

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

LongBuffer API:

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

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

Code

import java.nio.*;

public class EqualBuffer {
  public static final int capacity = 256;

  public static void main(String[] args) {
    LongBuffer longBuf = LongBuffer.allocate(capacity);
    IntBuffer IntBuf = IntBuffer.allocate(capacity);
    if (longBuf.equals(IntBuf)) {
      System.out.println("Equal");
    else {
      System.out.println("Not equal");
    }
    LongBuffer longBuf1 = LongBuffer.allocate(capacity);
    if (longBuf.equals(longBuf1)) {
      System.out.println("Equal");
    else {
      System.out.println("Not equal");
    }
    longBuf.put(9767767);
    longBuf.put(367745345);
    longBuf1.put(74556565);
    if (longBuf.equals(longBuf1)) {
      System.out.println("Equal");
    else {
      System.out.println("Not equal");
    }
  }
}

Output

C:\>jAva EqualBuffer
Not equal
Equal
Not equal

Download this code

Advertisement

Related Tags for Use of equals() method of LongBuffer 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 9, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com