VOOZH about

URL: https://www.geeksforgeeks.org/java/map-equals-method-in-java-with-examples/

⇱ Java Map equals() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java Map equals() Method

Last Updated : 11 Jul, 2025

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() Method

public 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.

Output:

👁 Output
Comment