In this example we will show how to check whether the specified key in a HashTable in Java.
Source Code
package com.beginner.examples;
import java.util.Hashtable;
public class KeyInHashTable {
public static void main(String[] args) {
// Create a HashTable object
Hashtable tables = new Hashtable();
tables.put("1", "A");
tables.put("2", "B");
boolean b = tables.containsKey("2"); // check whether the specified key in a HashTable
System.out.println(b);
}
}
Output:
true
References
Imported packages in Java documentation: