java.util.HashMap.containsValue() Method


Advertisements

Description

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

Declaration

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

public boolean containsValue(Object value)

Parameters

value − This is the value 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.HashMap.containsValue()

package com.tutorialspoint;

import java.util.*;

public class HashMapDemo {
   public static void main(String args[]) {
      
      // create hash map
      HashMap newmap = new HashMap();

      // populate hash map
      newmap.put(1, "tutorials");
      newmap.put(2, "point");
      newmap.put(3, "is best"); 

      // check existence of value 'point'
      System.out.println("Check if value 'point' exists: " + 
      newmap.containsValue("point"));
   }    
}

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

Check if value 'point' exists: true
java_util_hashmap.htm
Advertisements