ShortBuffer in java, Use of equals() method of ShortBuffer class in java.


 

ShortBuffer in java, Use of equals() method of ShortBuffer class in java.

In this tutorial, you will see how to use of equals() method of ShortBuffer class in java.

In this tutorial, you will see how to use of equals() method of ShortBuffer class in java.

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

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

ShortBuffer API:

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

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

Code

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

public class EqualsShortBuffer {
  public static void main(String[] argv{
ShortBuffer shortBuf =ShortBuffer.allocate(512);
FloatBuffer floatBuf =FloatBuffer.allocate(512);
    if (shortBuf.equals(floatBuf)) {
      System.out.println("Equal");
    else {
      System.out.println("Not equal");
    }
ShortBuffer shortBuf1=ShortBuffer.allocate(512);
    if (shortBuf.equals(shortBuf1)) {
      System.out.println("Equal");
    else {
      System.out.println("Not equal");
    }
    shortBuf.put((short9);
    shortBuf.put((short3);
    shortBuf.flip();
    shortBuf1.put((short9);
    shortBuf1.put((short3);
    shortBuf1.flip();
    if (shortBuf.equals(shortBuf1)) {
      System.out.println("Equal");
    else {
      System.out.println("Not equal");
    }
  }
}

Output

C:\>java EqualsShortBuffer
Not equal
Equal
Equal

Download this code

Ads