What is a WeakHashMap in Java ?

WeakHashMap is a class similar to IdentityHashMap. Internally, it is represented by a Hashtable.

It is not a synchronized class. We can make a WeakHashMap thread safe by using Collections.synchronizedMap() method. An entry in WeakHashMap is automatically removed when it is no longer in ordinary use.

The presence of a mapping for a given key does not prevent the key from being discarded by the garbage collector. WeakHashMap also permits null keys and null values.



You May Interest

What are the Differences Between a Vector and an ArrayList in Jav ...

What is the Difference Between DOM and SAX Parser in Java ?

How Can You Make an Object Eligible for Garbage Collection in Jav ...

How Will You Implement Error Page in JSP ?

How Will You Handle InterruptedException in Java ?