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 is a Livelock in Java ?

What are the Differences Between Internal and External Iterator i ...

How Will You Define the Scope of a Bean in Spring ?

What are the Different States of a Thread in Java ?

Java How To Find The Average Of 10 Numbers Using A While Loop