ShortBuffer in java, Use of hashCode() in short buffer.


 

ShortBuffer in java, Use of hashCode() in short buffer.

In this tutorial, you will see the use of hashCode() in short buffer.

In this tutorial, you will see the use of hashCode() in short buffer.

ShortBuffer in java, Use of hashCode() in short buffer.

In this tutorial, we will see how to use of hashCode() in short buffer.

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 new short buffer.
abstract ShortBuffer put(short s) The put(..) method write short value in short buffer.
 final int hashCode() The hashCode(..) method returns current hash Code of buffer.

  Code

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

public class ShortBuffHasCode{
  public static void main(String[] args) {
    ShortBuffer shortBuf = ShortBuffer.allocate(124);
    int i = shortBuf.hashCode();
    System.out.println("Before writing content the "
        "current hash code of buffer : " + i);
    shortBuf.put((short2222);
    shortBuf.flip();
    int i1 = shortBuf.hashCode();
    System.out.println("After writing content the "
        "current hash code of buffer : " + i1);
  }
}

Output

C:\>java ShortBuffHasCode
Before writing content the current hash code of buffer : 1794185345
After writing content the current hash code of buffer : 2253

Download this code

Ads