ByteBuffer hashCode() in Java

hashCode(): This method is available in java.nio.ByteBuffer class of Java.

Syntax:

int java.nio.ByteBuffer.hashCode()

This method returns the current hash code of this buffer. The hash code of a byte buffer depends only upon its remaining elements; that is, upon the elements from position() up to, and including, the element at the limit() - 1. 

Parameters: NA

Returns: The current hash code of this buffer.

Exceptions: NA

Approach

Java

import java.nio.ByteBuffer;

public class ByteBufferhashCode {
    public static void main(String[] args) {

        byte array[] = { 1234 };
        ByteBuffer bb = ByteBuffer.wrap(array);

        System.out.println(bb.hashCode());

    }
}

Output:

1045631


No comments:

Post a Comment