WeakHashMap remove Example

WeakHashMap class remove example. This example shows you how to use remove method.


WeakHashMap class remove example.public V remove(Object key) Removes the mapping for a key from this weak hash map if it is present. More formally, if this map contains a mapping from key k to value v such that (key==null ? k==null : key.equals(k)), that mapping is removed.

Here is the code

/**
 * @ # Remove.java
 * A class repersenting use to remove method 
 * of WeakHashMap class in java.util package
 * version 22 May 2008
 * author Rose India 
 */
import java.util.*;

public class Remove {

    public static void main(String args[]) {

        WeakHashMap map = new WeakHashMap();

        map.put(1"A");
        map.put(2"B");
        map.put(3"C");
        map.put(4"D");
        
        System.out.println("map = " + map);
        
        map.remove(3);
        System.out.println("map = " + map);
    }
}

Output
map = {4=D, 3=C, 2=B, 1=A}
map = {4=D, 2=B, 1=A}

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US