IdentityHashMap containsKey(Object) in Java

containsKey(Object): This method is available in java.util.IdentityHashMap class of Java.

Syntax:

boolean java.util.IdentityHashMap.containsKey(Object key)

This method takes one argument. This method tests whether the specified object reference is a key in this identity hashmap.

Parameters: One parameter is required for this method.

key: possible key.

Returns: true if the specified object reference is a key in this map.

Exceptions: NA

Approach

Java

import java.util.IdentityHashMap;

public class IdentityHashMapcontainsKey {

    public static void main(String args[]) {

        IdentityHashMap<String, Integer> identityHashMap =
new IdentityHashMap<String, Integer>();

        identityHashMap.put("Java", 1);
        identityHashMap.put("Hello", 2);

        Object key = "Hello";

        System.out.println(identityHashMap.containsKey(key));
    }

}

Output:

true


No comments:

Post a Comment