In this example we will show how to check if Hashtable object contains a particular value with contains method of Hashtable class.
Source Code
package com.beginner.examples;
import java.util.Hashtable;
public class CheckValueOfHashTableExample {
public static void main(String[] args) {
// Create a HashTable object
Hashtable hTable = new Hashtable();
// Put Key-value
hTable.put("1", "January");
hTable.put("2", "February");
hTable.put("3", "March");
//To check that the HashTable contains the specified value, use the containsValue() method
boolean b1 = hTable.containsValue("January");
boolean b2 = hTable.containsValue("April");
System.out.println("Value January:" + b1 + "nValue April:" + b2);
}
}
Output:
Value January:true
Value April:false
References
Imported packages in Java documentation: