remove(Object, Object): This method is available in java.util.IdentityHashMap class of Java.
Syntax:
boolean java.util.Map.remove(Object key, Object value)
This method takes two arguments. This method removes the entry for the specified key only if it is currently mapped to the specified value.
Parameters: Two parameters are required for this method.
key: key with which the specified value is associated.
value: value expected to be associated with the specified key.
Returns: true if the value was removed.
Throws:
1. UnsupportedOperationException - if the remove operation is not supported by this map.
2. ClassCastException - if the key or value is of an inappropriate type for this map.
3. NullPointerException - if the specified key or value is null, and this map does not permit null keys or values.
Approach
Java
import java.util.IdentityHashMap;public class IdentityHashMapremove2 {public static void main(String args[]) {IdentityHashMap<String, Integer> identityHashMap =new IdentityHashMap<String, Integer>();identityHashMap.put("Java", 1);identityHashMap.put("Hello", 2);Object key = "Java", value = 1;System.out.println(identityHashMap.remove(key, value));}}
Output:
true
No comments:
Post a Comment