IdentityHashMap remove(Object) in Java

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

Syntax:

V java.util.IdentityHashMap.remove(Object key)

This method takes one argument. This method removes the mapping for this key from this map if present.

Parameters: One parameter is required for this method.

key: key whose mapping is to be removed from the map.

Returns: the previous value associated with key, or null if there was no mapping for key.

Exceptions: NA

Approach

Java

import java.util.IdentityHashMap;

public class IdentityHashMapremove {

    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.remove(key));
    }

}

Output:

2


No comments:

Post a Comment