HashTable boolean contains(Object value) Method Example Program


Tests if some key maps into the specified value in this hashtable. This operation is more expensive than the containsKey method.
Note that this method is identical in functionality to containsValue, (which is part of the Map interface in the collections framework).

Program

package com.candidjava;

import java.util.Hashtable;

/**
 * @author: Hari Haran
 * @discription: The contains(Object value) method is used to test if some key
 *               maps into the specified value in this hashtable.
 */

public class HashTableContains {
	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.contains("Hari Haran");

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

Output

Hash table contains 'Hari Haran': true

Explanation

public boolean contains(Object value)
Tests if some key maps into the specified value in this hashtable. This operation is more expensive than the containsKey method.
Note that this method is identical in functionality to containsValue, (which is part of the Map interface in the collections framework).

Parameters:
value - a value to search for
Returns:
true if and only if some key maps to the value argument in this hashtable as determined by the equals method; false otherwise.
Throws:
NullPointerException - if the value is null


Related Post

Comments


©candidjava.com