Java AbstractMap hashCode() Method Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The hashCode() method of the AbstractMap class in Java is used to calculate a hash code value for a map. This hash code is based on the key-value mapping contained in the map. It ensures consistency such that two maps with the same entries have the same hash code.Example 1: Hash Code of a Non-Empty Map Java // Java program demonstrate the working of hashCode() import java.util.AbstractMap; import java.util.HashMap; import java.util.Map; public class Geeks { public static void main(String[] args) { // Create a HashMap Map<String, Integer> hm = new HashMap<>(); // Add key-value pairs hm.put("Java", 1); hm.put("Programnming", 2); hm.put("Language", 3); // Get hashCode System.out.println("Map: " + hm); System.out.println("HashCode: " + hm.hashCode()); } } OutputMap: {Programnming=2, Java=1, Language=3} HashCode: -95421541 Explanation: In the above example, it creates a HashMap and adds three key-value pairs to it. The hashCode() method calculates a unique integer value based on the keys and values in the map.Syntax of AbstractMap hashCode() Methodpublic int hashCode()Return Type: It returns an integer representing the hash code value of the map.Example 2: Hash Code of an Empty Map Java // Java programm to demonstrates the // hash code of an empty HashMap import java.util.AbstractMap; import java.util.HashMap; import java.util.Map; public class Geeks { public static void main(String[] args) { // creating an empty HashMap Map<String, Integer> hm1 = new HashMap<>(); System.out.println("Empty Map: " + hm1); System.out.println("HashCode of Empty Map: " + hm1.hashCode()); } } OutputEmpty Map: {} HashCode of Empty Map: 0 Explanation: The above program creates an empty HashMap without any key-value pairs. The hashCode() method returns 0 because no entries exist in the map. Create Quiz Comment C chinmoy lenka Follow 0 Improve C chinmoy lenka Follow 0 Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-HashMap Java-AbstractMap +3 More Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References7 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers1 min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like