Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Java AbstractMap hashCode() Method
Next article icon

Java AbstractMap equals() Method

Last Updated : 20 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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.

Java
// Java code to demonstrate the working of equals() import java.util.AbstractMap; import java.util.HashMap; import java.util.Map;  public class Geeks {     public static void main(String[] args)     {             // Creating three HashMap instances         Map<String, Integer> hm1 = new HashMap<>();         hm1.put("Geek1", 1);         hm1.put("Geek2", 2);         hm1.put("Geek3", 3);          Map<String, Integer> hm2 = new HashMap<>();         hm2.put("Geek3", 3);         hm2.put("Geek2", 2);         hm2.put("Geek1", 1);          Map<String, Integer> hm3 = new HashMap<>();         hm3.put("Geek1", 1);         hm3.put("Geek2", 2);         hm3.put("Geek4", 4);          System.out.println("First HashMap: " + hm1);         System.out.println("Second HashMap: " + hm2);         System.out.println("Third HashMap: " + hm3);                // Checking equality between the maps         System.out.println("Is hm1 equal to hm2? " + hm1.equals(hm2));         System.out.println("Is hm1 equal to hm3? " + hm1.equals(hm3));       } } 

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 

Next Article
Java AbstractMap hashCode() Method
author
chinmoy lenka
Improve
Article Tags :
  • Misc
  • Java
  • Java-Collections
  • Java - util package
  • Java-HashMap
  • Java-AbstractMap
Practice Tags :
  • Java
  • Java-Collections
  • Misc

Similar Reads

  • HashMap in Java
    In Java, HashMap is part of the Java Collections Framework and is found in the java.util package. It provides the basic implementation of the Map interface in Java. HashMap stores data in (key, value) pairs. Each key is associated with a value, and you can access the value by using the corresponding
    15+ min read
  • HashMap clear() Method in Java
    The clear() method of the HashMap class in Java is used to remove all of the elements or mappings (key-value pairs) from a specified HashMap. Example 2: Here, we will use the clear() method to clear a HashMap of Integer keys and String values. [GFGTABS] Java // Clearing HashMap of Integer keys // an
    2 min read
  • HashMap clone() Method in Java
    The clone() method of the HashMap class in Java is used to create a shallow copy of the specified HashMap. The method returns a new HashMap that contains the same key-value mappings as the original HashMap. Example 1: Here, we will use the clone() method to clone a HashMap of Integer keys and String
    2 min read
  • HashMap compute() Method in Java
    The compute(Key, BiFunction) method of the HashMap class in Java is used to update or compute a value for a specific key. It tries to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping). If the remapping function passed to compute() returns n
    4 min read
  • HashMap containsKey() Method in Java
    The java.util.HashMap.containsKey() method is used to check whether a particular key is being mapped into the HashMap or not. It takes the key element as a parameter and returns True if that element is mapped in the map. Syntax: Hash_Map.containsKey(key_element)Parameters: The method takes just one
    2 min read
  • Java HashMap containsValue() Method
    In Java, the containsValue() method of the HashMap class is used to check whether a particular value is being mapped by a single or more than one key in the HashMap. Example 1: This example demonstrates how the containsValue() method works when String values are mapped to integer keys. [GFGTABS] Jav
    2 min read
  • HashMap entrySet() Method in Java
    The entrySet() method of the HashMap class in Java is used to create a set view of the mappings contained in the HashMap. This method allows us to iterate over the key-value pairs in the map or convert them into a set. Example 1: Here, we will use the entrySet() method to view the mappings in a Hash
    2 min read
  • HashMap get() Method in Java
    The java.util.HashMap.get() method of HashMap class is used to retrieve or fetch the value mapped by a particular key mentioned in the parameter. It returns NULL when the map contains no such mapping for the key. Syntax: Hash_Map.get(Object key_element)Parameter: The method takes one parameter key_e
    2 min read
  • Java HashMap put() Method
    The put() method of the Java HashMap class is used to add or update the key-value pairs in the map. If the key already exists in the map, the previous value associated with the key is replaced by the new value and If the key does not exist, the new key-value pair is added to the map. Syntax of HashM
    2 min read
  • Java HashMap putAll() Method
    The putAll() method of the Java HashMap class is used to copy all key-value mappings from another map to the existing map. If a key exists in both maps, its value is updated with the value from the source map. Otherwise, new key-value pairs are added. Example 1: This example demonstrates copying all
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences