SortedMap hashCode() method in Java with Examples Last Updated : 30 Sep, 2019 Comments Improve Suggest changes Like Article Like Report The hashCode() method of SortedMap interface in Java is used to generate a hashCode for the given map containing key and values. Syntax: int hashCode() Parameters: This method has no argument. Returns: This method returns the hashCode value for the given map. Note: The hashCode() method in SortedMap is inherited from the Map interface in Java. Below programs show the implementation of int hashCode() method. Program 1: Java // Java code to show the implementation of // hashCode() method in SortedMap interface import java.util.*; public class GfG { // Driver code public static void main(String[] args) { // Initializing a SortedMap // of type TreeMap SortedMap<Integer, String> map = new TreeMap<>(); map.put(1, "One"); map.put(3, "Three"); map.put(5, "Five"); map.put(7, "Seven"); map.put(9, "Ninde"); System.out.println(map); int hash = map.hashCode(); System.out.println(hash); } } Output: {1=One, 3=Three, 5=Five, 7=Seven, 9=Ninde} 238105666 Program 2: Below is the code to show implementation of hashCode(). Java // Java code to show the implementation of // hashCode method in SortedMap interface import java.util.*; public class GfG { // Driver code public static void main(String[] args) { // Initializing a SortedMap // of type TreeMap SortedMap<String, String> map = new TreeMap<>(); map.put("1", "One"); map.put("3", "Three"); map.put("5", "Five"); map.put("7", "Seven"); map.put("9", "Ninde"); System.out.println(map); int hash = map.hashCode(); System.out.println(hash); } } Output: {1=One, 3=Three, 5=Five, 7=Seven, 9=Ninde} 238105618 Reference: Oracle Docs Comment More infoAdvertise with us Next Article SortedMap hashCode() method in Java with Examples gopaldave Follow Improve Article Tags : Java Java - util package Java-Functions Java-SortedMap Practice Tags : Java Similar Reads SortedSet hashCode() method in Java with Examples The hashCode() method of SortedSet in Java is used to get the hashCode value for this instance of the SortedSet. It returns an integer value which is the hashCode value for this instance of the SortedSet. Syntax: public int hashCode() Parameters: This function has no parameters. Returns: The method 2 min read Short hashCode() method in Java with Examples The hashCode() method of Short class is a built in method in Java which is used to return the hash code of the ShortObject. Note: The hashCode() returns the same value as intValue(). Syntax ShortObject.hashCode() Return Value: It return an int value which represents the hashcode of the specified Sho 2 min read MonthDay hashCode() method in Java with Examples hashCode() method of the MonthDay class used to get hashCode for this MonthDay. The hashcode is always the same if the object doesnât change. Hashcode is a unique code generated by the JVM at time of object creation. It can be used to perform some operation on hashing related algorithm like a hashta 1 min read 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 2 min read Stack hashCode() method in Java with Example The Java.util.Stack.hashCode() method in Java is used to get the hashcode value of this Stack. Syntax: Stack.hashCode() Parameters: The method does not take any parameter. Return Value: The method returns hash code value of this Stack which is of Integer type. Below programs illustrate the Java.util 2 min read Like