Java Hashmap containsValue() Method
What is a Hashmap?
Hashmap was first introduced in Java 1.2.The Hashmap class is included in the java.util package.The data in a hashmap is stored in two parts: the key and the value, which can be accessed using an index of another type.A hashmap have unique keys , inserting a duplicate key will replace the data of the key. Hashmap class have many inbuilt method, one of those method is Java Hashmap containsValue() Method.
To know more about Hashmap containsValue() Method read the complete article
Java Hashmap containsValue() Method
The hashmap containsValue() method checks if the hashmap have the mapping of the given value with one or more key or not. It takes one parameter. Below in this page you can find it’s syntax, return values, parameters with detailed examples.
Syntax :
hashmap.containsValue(object Value);
Parameters :
Object Value: The Value whose mapping is to be find.
Return values :
True : If value is mapped with one or more than one key. False : If value is not mapped to any of the keys.
Hashmap containsValue() Method Examples
Example :
import java.util.*; public class Main { public static void main (String[]args) { // Creating an empty HashMap HashMap < Integer, String > hash_map = new HashMap < Integer, String > (); // Mapping string values to int keys hash_map.put (10, "Java"); hash_map.put (20, "Hashmap"); hash_map.put (25, "containsValue"); hash_map.put (30, "method"); //checking if the value 'Java' is mapped or not System.out.println ("'Java' is mapped : " + hash_map.containsValue ("Java")); // checking if the value 'Python' is mapped or not System.out.println ("'Python' is mapped' : " + hash_map.containsValue ("Python")); } }
Output :
'Java' is mapped : true 'Python' is mapped' : false
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment