java.util.WeakHashMap.containsValue() Method



Description

The containsValue(Object value) method is used to return true if this map, maps one or more keys to the specified value.

Declaration

Following is the declaration for java.util.WeakHashMap.containsValue() method.

public boolean containsValue(Object value)

Parameters

value − The value is the input whose presence in this map is to be tested.

Return Value

The method call returns true if this map maps one or more keys to the specified value.

Exception

NA

Example

The following example shows the usage of java.util.WeakHashMap.containsValue() method.

package com.tutorialspoint;

import java.util.Map;
import java.util.WeakHashMap;

public class WeakHashMapDemo {
   public static void main(String[] args) { 
      Map<String, String> weakHashMap = new WeakHashMap<String, String>();

      // put keys and values in the Map      
      weakHashMap.put("1", "first");
      weakHashMap.put("2", "two");
      weakHashMap.put("3", "three");

      // check existence of value "three"
      System.out.println("Checking value 'three'");
      System.out.println(weakHashMap.containsValue("three"));
   }    
}

Let us compile and run the above program, this will produce the following result.

Checking value 'three'
true
java_util_weakhashmap.htm
Advertisements