Java Map equals() Method Last Updated : 11 Jul, 2025 Comments Improve Suggest changes 5 Likes Like Report The equals() method of Map interface in Java is used to check if two maps are equal. Two maps are considered equal if they meet the following conditions. Both maps must have the same size.Both maps must contain identical key-value pairs. (It means every key in one map must be associated with the same value as in the other map) Syntax of equals() Methodpublic boolean equals(Object o)Parameter: This method takes an object "o" which is compared with equality with the current map.Return Type: This method returns "true" if the specified object is equal to the current map, otherwise it returns "false".Example: This example demonstrates how to use the equals() method to check if two HashMap objects have identical key-value pairs. Java // Java Program to demonstrates the working of equals() import java.util.HashMap; import java.util.Map; public class Geeks { public static void main(String[] args) { // Create the first HashMap and // add key-value pairs Map<Integer, String> hm1 = new HashMap<>(); hm1.put(1, "Geek1"); hm1.put(2, "Geek2"); hm1.put(3, "Geek3"); // Create the second HashMap // and add key-value pairs Map<Integer, String> hm2 = new HashMap<>(); hm2.put(1, "Geek1"); hm2.put(2, "Geek2"); hm2.put(3, "Geek3"); // Create the Third HashMap // and add key-value pairs Map<Integer, String> hm3 = new HashMap<>(); hm3.put(1, "Geek1"); hm3.put(2, "Geek4"); hm3.put(3, "Geek5"); System.out.println("First HashMap: " + hm1); System.out.println("Second HashMap: " + hm2); // Compare the First and the // Second HashMap for equality System.out.println("Are the maps equal? " + hm1.equals(hm2)); System.out.println("First HashMap: " + hm1); System.out.println("Third HashMap: " + hm3); // Compare the First and the // Third HashMap for equality System.out.println("Are the maps equal? " + hm1.equals(hm3)); } } Output: Comment G gopaldave Follow 5 Improve G gopaldave Follow 5 Improve Article Tags : Java Java-Collections Java-Functions Java-HashMap java-map +1 More Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings8 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java9 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java5 min readJava Comparator Interface6 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 Java10 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ 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