Java Hashtable.containsKey(Object key)

Syntax

Hashtable.containsKey(Object key) has the following syntax.

public boolean containsKey(Object key)

Example

In the following code shows how to use Hashtable.containsKey(Object key) method.


/*from ww  w. j  a  v a  2s.c o m*/
import java.util.Hashtable;

public class Main {
   public static void main(String args[]) {
      Hashtable<Integer, String> htable = new Hashtable<Integer, String>();

      // put values into the table
      htable.put(1, "A");
      htable.put(2, "B");
      htable.put(3, "C");
      htable.put(4, "from java2s.com");

      
      // check if table contains key "3"
      boolean isavailable=htable.containsKey(3);

      // display search result
      System.out.println("Hash table contains key '3': "+isavailable);      
   }    
}

The code above generates the following result.