WeakHashMap containsValue(Object) in Java

containsValue(Object): This method is available in java.util.WeakHashMap class of Java.

Syntax:

boolean java.util.WeakHashMap.containsValue(Object value)

This method takes one argument. This method returns true if this map maps one or more keys to the specified value.

Parameters: One parameter is required for this method.

value: value whose presence in this map is to be tested.

Returns: true if this map maps one or more keys to the specified value.

Exceptions: NA

Approach

Java

import java.util.WeakHashMap;

public class WeakHashMapcontainsValue {
    public static void main(String[] args) {

        WeakHashMap<String, String> weakHashMap =
new WeakHashMap<String, String>();

        weakHashMap.put("Java", "Program");
        weakHashMap.put("Hello", "World");

        Object value = "Program";

        System.out.println(weakHashMap.containsValue(value));
    }
}

Output:

true


No comments:

Post a Comment