In this article, we will learn
WeakHashMap class from the java.util package with examples.
What Will We Learn?
WeakHashMapClass Constructor Summary
WeakHashMapClass Constructor Methods
1. WeakHashMap Class Overview
WeakHashMap is a Hash table-based implementation of the Map interface with weak keys. An entry in a
WeakHashMap will automatically be removed when its key is no longer in ordinary use. Both null values and the null key are supported. This class has performance characteristics similar to those of the HashMap class and has the same efficiency parameters of initial capacity and load factor. Like most collection classes, this class is not synchronized. A synchronized
WeakHashMap may be constructed using the
Collections.synchronizedMap method. Weak Reference − if the only references to an object are weak references, the garbage collector can reclaim the object’s memory at any time. It doesn’t have to wait until the system runs out of memory. Usually, it will be freed the next time the garbage collector runs. This class is a member of the Java Collections Framework.