IdentityHashMap isEmpty() Method in Java Last Updated : 08 Mar, 2024 Comments Improve Suggest changes Like Article Like Report 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. Return Value: The method returns a boolean true if the map is empty or does not contain any mapping pairs else boolean false. The below programs illustrate the working of java.util.IdentityHashMap.isEmpty() method: Program 1: Mapping String Values to Integer Keys. Java // Java code to illustrate the isEmpty() 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("The Mappings are: "+ identity_hash); // Checking for the emptiness of Map System.out.println("Is the map empty? "+ identity_hash.isEmpty()); } } OutputThe Mappings are: {Geeks=20, Welcomes=25, You=30, 4=15} Is the map empty? false Program 2: For an empty IdentityHashMap Java // Java code to illustrate the isEmpty() 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>(); // Displaying the IdentityHashMap System.out.println("The Mappings are: "+ identity_hash); // Checking for the emptiness of Map System.out.println("Is the map empty? "+ identity_hash.isEmpty()); } } OutputThe Mappings are: {} Is the map empty? true Note: The same operation can be performed with any type of Mappings with variation and combination of different data types. All methods of Java.util.IdentityHashMap Class Comment More infoAdvertise with us chinmoy lenka Follow Improve Article Tags : Misc Java Java-Collections Java-Functions java-IdentityHashMap +1 More Practice Tags : JavaJava-CollectionsMisc 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 Like