A special data structure in Java, a WeakHashMap is a hashtable-based Map with weak keys, meaning when a key has been discarded its entry is effectively removed from the map.
Java's WeakHashMap
is a hashtable-based Map
with weak keys, meaning when a key has been discarded its entry is effectively removed from the map.
This class is intended primarily for use with key objects whose equals methods test for object identity using the
==
operator. Once such a key is discarded it can never be recreated, so it is impossible to do a lookup of that key in aWeakHashMap
at some later time and be surprised that its entry has been removed.