Java Utility Library

Java IdentityHashMap - entrySet() Method



The java.util.IdentityHashMap.entrySet() method returns a Set view of the mappings contained in this map. Each element in the returned set is a reference-equality-based Map.Entry. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa.

Syntax

public Set<Map.Entry<K,V>> entrySet()

Here, K and V are the type of key and value respectively maintained by the container.


Parameters

No parameter is required.

Return Value

Returns a set view of the identity-mappings contained in this map.

Exception

NA

Example:

In the example below, the java.util.IdentityHashMap.entrySet() method returns a view of the mappings contained in the given map.

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>();

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

    //printing the content of the map
    System.out.println("MyMap contains: " + MyMap);

    //creating a set view of mapping of the map
    Set SetView = MyMap.entrySet();

    //printing the set view of mapping
    System.out.println("SetView contains: " + SetView);
  }
}

The output of the above code will be:

MyMap contains: {105=Sam, 101=John, 102=Marry, 104=Jo, 103=Kim}
SetView contains: [105=Sam, 101=John, 102=Marry, 104=Jo, 103=Kim]

❮ Java.util - IdentityHashMap