K - - the type of the key objectV - - the type of the value objectpublic class WeakValueHashMap<K,V>
extends java.util.AbstractMap<K,V>
A HashMap doesn't help here since it will keep hard references for key and
value objects. A WeakHashMap doesn't either, because it keeps weak references to the
key objects, but we want to track the value objects.
This implementation of a Map uses a WeakReference to the value objects. Once the
garbage collector decides it wants to finalize a value object, it will be removed from the
map automatically.
| Constructor and Description |
|---|
WeakValueHashMap()
Creates a WeakValueHashMap with an initial capacity of 1
|
WeakValueHashMap(int capacity)
Creates a WeakValueHashMap with a desired initial capacity
|
WeakValueHashMap(java.util.Map<? extends K,? extends V> map)
Creates a WeakValueHashMap and copies the content from an existing map
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
boolean |
containsKey(java.lang.Object key) |
boolean |
containsValue(java.lang.Object value) |
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet() |
V |
get(java.lang.Object key) |
java.util.Set<K> |
keySet() |
V |
put(K key,
V value) |
V |
remove(java.lang.Object key) |
int |
size() |
java.util.Collection<V> |
values() |
clone, equals, hashCode, isEmpty, putAll, toStringpublic WeakValueHashMap(int capacity)
capacity - - the initial capacitypublic WeakValueHashMap()
public V get(java.lang.Object key)
public V remove(java.lang.Object key)
public void clear()
public boolean containsKey(java.lang.Object key)
public boolean containsValue(java.lang.Object value)
public java.util.Set<K> keySet()
public int size()