The hashCode() method of java.nio.ByteBuffer class is used to return 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 limit() – 1.
Because buffer hash codes are content-dependent, it is inadvisable to use buffers as keys in hash maps or similar data structures unless it is known that their contents will not change.
public int hashCode()
Return Value: This method returns the current hash code of this buffer.
Below are the examples to illustrate the hashCode() method:
Original ByteBuffer: 10 20 30 Byte Value: -219122491
Byte Value: -293403007
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.