Java – WeakHashMap Class

Java WeakHashMap Class methods, constructors, variables available in Java 8 release are listed below. We will publish example program on each methods ASAP.

Constructors in Java WeakHashMap Class

S.No Constructor & Description
1 WeakHashMap()

Constructs a new, empty WeakHashMap with the default initial capacity (16) and load factor (0.75).
2 WeakHashMap(int initialCapacity)

Constructs a new, empty WeakHashMap with the given initial capacity and the default load factor (0.75).
3 WeakHashMap(int initialCapacity, float loadFactor)

Constructs a new, empty WeakHashMap with the given initial capacity and the given load factor.
4 WeakHashMap(Map<? extends K,? extends V> m)

Constructs a new WeakHashMap with the same mappings as the specified map.

Methods in Java WeakHashMap Class

S.No Method & Description
1 void clear()

Removes all of the mappings from this map.
2 boolean containsKey(Object key)

Returns true if this map contains a mapping for the specified key.
3 boolean containsValue(Object value)

Returns true if this map maps one or more keys to the specified value.
4 Set<Map.Entry<K,V>> entrySet()

Returns a Set view of the mappings contained in this map.
5 void forEach(BiConsumer<? super K,? super V> action)

Performs the given action for each entry in this map until all entries have been processed or the action throws an exception.
6 V get(Object key)

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
7 boolean isEmpty()

Returns true if this map contains no key-value mappings.
8 Set<K> keySet()

Returns a Set view of the keys contained in this map.
9 V put(K key, V value)

Associates the specified value with the specified key in this map.
10 void putAll(Map<? extends K,? extends V> m)

Copies all of the mappings from the specified map to this map.
11 V remove(Object key)

Removes the mapping for a key from this weak hash map if it is present.
12 void replaceAll(BiFunction<? super K,? super V,? extends V> function)

Replaces each entry’s value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception.
13 int size()

Returns the number of key-value mappings in this map.
14 Collection<V> values()

Returns a Collection view of the values contained in this map.

Ask your questions in eHowToNow Forum

Post your technical, non-technical doubts, questions in our site. Get answer as soon as possible, meanwhile you can help others by answering, unanswered questions.
To Ask new Question : Ask Question
Check our existing discussions : Questions & Answers

  1. Java – LongStream Interface
  2. Java LinkedHashSet spliterator() method with example
  3. Java – RunnableFuture Interface
  4. Java – DoubleAccumulator Class
  5. Java – IntSummaryStatistics Class
  6. Java – Spliterators.AbstractDoubleSpliterator Class
  7. Java – Timer Class
  8. Java – AbstractQueue Class
  9. Java – ThreadLocalRandom Class
  10. Java – DoublePredicate Interface
  11. How to validate Email Address using Java Regular Expression
  12. Java – CompletableFuture.AsynchronousCompletionTask Interface
  13. Java ArrayList addAll(Collection< ? extends E> c) method with example
  14. Java ArrayList forEach() method with example
  15. Java – ToIntFunction Interface

Be the first to comment

Leave a Reply