VOOZH about

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

⇱ Java AbstractMap equals() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java AbstractMap equals() Method

Last Updated : 11 Jul, 2025

The equals() method of the Java AbstractMap class is used to check equality between two maps. It compares the key-value pair in the current map with the key-value pair of the specified map.

Syntax of AbstarctMap equals() Method

public boolean equals(Object o)

  • Parameter: The Object to be compared with the current map.
  • Return Type: Return "true" if the specified object is equal to the current map, otherwise return "false".

Example: This example demonstrates how the equals() method checks for equality between different HashMap instances based on their key-value mapping.


Output
First HashMap: {Geek3=3, Geek2=2, Geek1=1}
Second HashMap: {Geek3=3, Geek2=2, Geek1=1}
Third HashMap: {Geek4=4, Geek2=2, Geek1=1}
Is hm1 equal to hm2? true
Is hm1 equal to hm3? false
Comment