java.util.IdentityHashMap.remove() Method

Advertisements


Description

The remove(Object key) method is used to remove the mapping for this key from this map if present.

Declaration

Following is the declaration for java.util.IdentityHashMap.remove() method.

public V remove(Object key)

Parameters

  • key--This is the key whose mapping is to be removed from the map.

Return Value

The method call returns the previous value associated with specified key, or null if there was no entry for key.

Exception

  • NA

Example

The following example shows the usage of java.util.IdentityHashMap.remove()

package com.tutorialspoint;

import java.util.*;

public class IdentityHashMapDemo {
   public static void main(String args[]) {
      // create identity hash 
      IdentityHashMap ihmap = new IdentityHashMap();
                 
      // populate the ihmap
      ihmap.put(1, "java");
      ihmap.put(2, "util");
      ihmap.put(3, "package");
      
      System.out.println("Value of ihmap before: " + ihmap);
      
      // remove element at key 2
      ihmap.remove(2);
      
      System.out.println("Value of ihmap after remove: " + ihmap);
   }    
}

Let us compile and run the above program, this will produce the following result.

Value of ihmap before: {1=java, 3=package, 2=util}
Value of ihmap after remove: {1=java, 3=package}



Advertisements
Advertisements