Java Utility Library

Java IdentityHashMap - isEmpty() Method



The java.util.IdentityHashMap.isEmpty() method is used to check whether this identity hash map contains no key-value mappings. It returns true if this map contains no mapping, else returns false.

Syntax

public boolean isEmpty()

Parameters

No parameter is required.

Return Value

Returns true if this identity hash map contains no key-value mappings.

Exception

NA

Example:

In the example below, the java.util.IdentityHashMap.isEmpty() method is used to check whether the given identity hash map is empty or not.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a identity hash map
    IdentityHashMap<Integer, String> MyMap = new IdentityHashMap<Integer, String>();

    //checking for empty
    System.out.println("Is MyMap empty?: "+ MyMap.isEmpty());

    //populating the map
    MyMap.put(101, "John");
    MyMap.put(102, "Marry");
    MyMap.put(103, "Kim");
    MyMap.put(104, "Jo");

    //checking for empty
    System.out.println("Is MyMap empty?: "+ MyMap.isEmpty());
  }
}

The output of the above code will be:

Is MyMap empty?: true
Is MyMap empty?: false

❮ Java.util - IdentityHashMap