HashTable boolean containsValue(Object value) Method Example Program


Returns true if this hashtable maps one or more keys to this value.
Note that this method is identical in functionality to contains (which predates the Map interface).

Program

package com.candidjava;

import java.util.Hashtable;

/**
 * @author: Hari Haran
 * @discription: The containsValue(Object value) method is used to test if this
 *               Hashtable maps one or more keys to this value.
 */

public class HashTableContainsValue {
	public static void main(String args[]) {

		Hashtable<Integer, String> ht = new Hashtable<Integer, String>();

		ht.put(1, "Anand");
		ht.put(2, "Hari Haran");
		ht.put(3, "Kamal");
		ht.put(4, "Karthikeyan");
		ht.put(5, "Mohan");
		ht.put(6, "Vinoth");
		ht.put(7, "Hari Haran");

		boolean isavailable = ht.containsValue("Hari Haran");

		System.out.println("Hash table contains value 'Hari Haran': "
				+ isavailable);
	}
}

Output

Hash table contains value 'Hari Haran': true

Explanation

public boolean containsValue(Object value)
Returns true if this hashtable maps one or more keys to this value.
Note that this method is identical in functionality to contains (which predates the Map interface).

Specified by:
containsValue in interface Map<K,V>
Parameters:
value - value whose presence in this hashtable is to be tested
Returns:
true if this map maps one or more keys to the specified value
Throws:
NullPointerException - if the value is null


Related Post

Comments


©candidjava.com