In this example we will show how to check if a value is contained in a HashMap in Java.
Source Code
package com.beginner.examples;
import java.util.HashMap;
public class ValueInHashMap {
public static void main(String[] args) {
// Create a HashMap
HashMap maps = new HashMap();
maps.put("a", "1");
maps.put("b", "2");
boolean b = maps.containsValue("1"); // check if a value is contained in a HashMap
System.out.println(b);
}
}
Output:
true
References
Imported packages in Java documentation: