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:
IdentityHashMap isEmpty() Method in Java
Next article icon

IdentityHashMap hashCode() Method in Java

Last Updated : 24 Jul, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report

The java.util.IdentityHashMap.hashCode() method in Java is used to fetch the hash code value of a particular this IdentityHashMap. A map consists of a number of buckets to store the key-value pair. Each bucket has a unique identity and when a key-value pair is inserted into a bucket, the key’s hashcode is matched with the identifier of the bucket, and if its a match the pair is stored successfully. This is how the hash code works.

Syntax:

Identity_HashMap.hashCode()

Parameters: The method does not accept any parameters.

Return Value: The method returns the hashcode value of the map.

Below programs are used to illustrate the working of java.util.IdentityHashMap.hashCode() Method:

Program 1: Mapping String Values to Integer Keys.




// Java code to illustrate the hashCode() method
import java.util.*;
  
public class Identity_Hash_Map_Demo {
    public static void main(String[] args)
    {
  
        // Creating an empty IdentityHashMap
        IdentityHashMap<Integer, String> identity_hash = 
                   new IdentityHashMap<Integer, String>();
  
        // Mapping string values to int keys
        identity_hash.put(10, "Geeks");
        identity_hash.put(15, "4");
        identity_hash.put(20, "Geeks");
        identity_hash.put(25, "Welcomes");
        identity_hash.put(30, "You");
  
        // Displaying the IdentityHashMap
        System.out.println("Initial Mappings are: "
                           + identity_hash);
  
        // Getting the hashcode value for the map
        System.out.println("The hashcode value of the map: "
                                + identity_hash.hashCode());
    }
}
 
 
Output:
  Initial Mappings are: {10=Geeks, 30=You, 20=Geeks, 25=Welcomes, 15=4}  The hashcode value of the map: 2043437408  

Program 2: Mapping Integer Values to String Keys.




// Java code to illustrate the hashCode() method
import java.util.*;
  
public class Identity_Hash_Map_Demo {
    public static void main(String[] args)
    {
  
        // Creating an empty IdentityHashMap
        Map<String, Integer> identity_hash = 
                    new IdentityHashMap<String, Integer>();
  
        // Mapping int values to string keys
        identity_hash.put("Geeks", 10);
        identity_hash.put("4", 15);
        identity_hash.put("Geeks", 20);
        identity_hash.put("Welcomes", 25);
        identity_hash.put("You", 30);
  
        // Displaying the IdentityHashMap
        System.out.println("Initial Mappings are: "
                           + identity_hash);
  
        // Getting the hashcode value for the map
        System.out.println("The hashcode value of the map: "
                                + identity_hash.hashCode());
    }
}
 
 
Output:
  Initial Mappings are: {Geeks=20, Welcomes=25, You=30, 4=15}  The hashcode value of the map: 751311572  

Note: The same operation can be performed with any type of Mapping with variation and combination of different data types.



Next Article
IdentityHashMap isEmpty() Method in Java
author
chinmoy lenka
Improve
Article Tags :
  • Java
  • Java-Collections
  • Java-Functions
  • java-IdentityHashMap
Practice Tags :
  • Java
  • Java-Collections

Similar Reads

  • IdentityHashMap class in Java
    The IdentityHashMap implements Map interface using Hashtable, using reference-equality in place of object-equality when comparing keys (and values). This class is not a general-purpose Map implementation. While this class implements the Map interface, it intentionally violates Map's general contract
    13 min read
  • IdentityHashMap clear() Method in Java
    The java.util.IdentityHashMap.clear() method in Java is used to clear and remove all of the elements or mappings from a specified map. Syntax: Identity_HashMap.clear() Parameters: The method does not accept any parameters. Return Value: The method does not return any value. Below programs are used t
    2 min read
  • IdentityHashMap clone() Method in Java
    The java.util.IdentityHashMap.clone() method is used to return a shallow copy of the mentioned hash map. It just creates a copy of the map. Syntax: Identity_HashMap.clone() Parameters: The method does not take any parameters. Return Value: The method just returns a copy of the hash map. Below progra
    2 min read
  • IdentityHashMap containsKey() Method in Java
    The java.util.IdentityHashMap.containsKey() method is used to check whether a particular key is being mapped into the IdentityHashMap or not. It takes the key element as a parameter and returns True if that element is mapped in the map. Syntax: Identity_HashMap.containsKey(key_element) Parameters: T
    2 min read
  • IdentityHashMap containsValue() Method in Java
    The java.util.IdentityHashMap.containsValue() method is used to check whether a particular value is being mapped by a single or more than one key in the IdentityHashMap. It takes the Value as a parameter and returns True if that value is mapped by any of the keys in the map. Syntax: Identity_HashMap
    2 min read
  • IdentityHashMap entrySet() Method in Java
    The java.util.IdentityHashMap.entrySet() method in Java is used to create a set out of the same elements contained in the map. It basically returns a set view of the identity hash map or we can create a new set and store the map elements into them. Syntax: Identity_HashMap.entrySet() Parameters: The
    2 min read
  • IdentityHashMap equals() Method in Java
    The java.util.IdentityHashMap.equals() method in Java is used to check for equality between two maps. It verifies whether the elements of one map passed as a parameter is equal to the elements of this map or not. Syntax: ihashmap1.equals(ihashmap2) Parameters: The method accepts one parameter ihashm
    2 min read
  • IdentityHashMap get() Method in Java
    The java.util.IdentityHashMap.get() method of IdentityHashMap 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: IdentityHashMap.get(Object key_element) Parameter: The method t
    2 min read
  • IdentityHashMap hashCode() Method in Java
    The java.util.IdentityHashMap.hashCode() method in Java is used to fetch the hash code value of a particular this IdentityHashMap. A map consists of a number of buckets to store the key-value pair. Each bucket has a unique identity and when a key-value pair is inserted into a bucket, the key's hashc
    2 min read
  • IdentityHashMap isEmpty() Method in Java
    The java.util.IdentityHashMap.isEmpty() method of IdentityHashMap class is used to check for the emptiness of the map. The method returns True if no key-value pair or mapping is present in the map else False. Syntax: Identity_Hash_Map.isEmpty()Parameters: The method does not take any parameters. Ret
    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