ShortBuffer hashCode() Method in Java with Examples
The hashCode() method of java.nio.ShortBuffer is used to return the hash code for a particular buffer.
The hash code of a short 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.
Syntax:
public int hashCode()
Parameters: The method does not take any parameters.
Return Value: The method returns the current hash code of the buffer.
Below programs illustrate the use of hashCode() method:
Program 1:
// Java program to demonstrate // compareTo() method import java.nio.*; import java.util.*; public class GFG { public static void main(String[] args) { // create short object and assign value to it short shortNum1 = 150; Short ShortObj1 = new Short(shortNum1); // returns hashcode int hcode = ShortObj1.hashCode(); System.out.println("Hashcode for this Short ShortObj1 = " + hcode); } } |
Hashcode for this Short ShortObj1 = 150
Program 2:
// Java program to demonstrate // compareTo() method import java.nio.*; import java.util.*; public class GFG { public static void main(String[] args) { // create short object and assign value to it short shortNum1 = 6010; Short ShortObj1 = new Short(shortNum1); // returns hashcode int hcode = ShortObj1.hashCode(); System.out.println("Hashcode for this Short ShortObj1 = " + hcode); } } |
Hashcode for this Short ShortObj1 = 6010
Reference: https://docs.oracle.com/javase/9/docs/api/java/nio/ShortBuffer.html#hashCode–
Recommended Posts:
- ShortBuffer compact() method in Java With Examples
- ShortBuffer order() Method in Java with Examples
- ShortBuffer compareTo method in Java with Examples
- ShortBuffer allocate() method in Java With Examples
- ShortBuffer mark() method in Java with Examples
- ShortBuffer arrayOffset() method in Java With Examples
- ShortBuffer toString() method in Java with Examples
- ShortBuffer asReadOnlyBuffer() method in Java with Examples
- ShortBuffer rewind() method in Java with Examples
- ShortBuffer array() Method in Java with Examples
- ShortBuffer equals() method in Java with Examples
- ShortBuffer hasArray() method in Java with Examples
- ShortBuffer put(int, short) method in Java With Examples
- ShortBuffer slice() method in Java with Examples
- ShortBuffer isDirect() Method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



