Home Tutorial Java Core HashMap Example of containsValues method of HashMap.

 
 

Share on Google+Share on Google+
Example of containsValues method of HashMap.
Posted on: April 5, 2011 at 12:00 AM
Advertisement
Example of containsValues method of HashMap.

Example of containsValues method of HashMap.

The containsValues is a method of HashMap class. It always returns boolean value. It checks, whether the values is present in HashMap or not. 

If the given values is present in map, than is returns true othewise false.

Code

HashMapContainsValue.java

package net.roseindia.java;

import java.util.HashMap;

public class HashMapContainsValue{

public static void main(String[] arr) {

/* Create object of HashMap */

HashMap<Integer, String> obMap = new HashMap<Integer, String>();

/* Add value in HashMap */

obMap.put(new Integer(1), "Bharat");

obMap.put(new Integer(2), "Gyan");

obMap.put(new Integer(4), "Vrishti");

obMap.put(new Integer(3), "Sarika");

obMap.put(new Integer(5), "Rohit");

obMap.put(new Integer(6), "Parineeta");

/* Check values present in HashMap or not */

System.out.println("Returns :" + obMap.containsValue("Vrishti"));

System.out.println("Returns :" +obMap.containsValue("Ankita")); } }

Output :

Returns :true

Returns :false

Advertisement

Related Tags for Example of containsValues method of HashMap.:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 5, 2011

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com