BACK
This program Hash Table used boolean value is availbale using boolean() method.
Example Program
import java.util.Hashtable; public class HashTableboolean { public static void main(String[] args) { // create two has table Hashtable htable = new Hashtable(); // put value into table htable.put(1, "Dog"); htable.put(2, "Cat"); htable.put(3, "Cow"); htable.put(4, "Donkey"); // check if table contain a value boolean isavailable = htable.containsValue("Cat"); // display search list available System.out.println("Hash table contains a value 'Cat': " + isavailable); } }
Output
Hash table contains a value ‘Cat’: 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