Java Collection Tutorial - Java Hashtable.contains(Object value)


Hashtable.contains(Object value) has the following syntax.

public boolean contains(Object value)


In the following code shows how to use Hashtable.contains(Object value) method.

/*from   www.j  a  v a2s  .com*/

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");

      // check if table contains "C"
      boolean isavailable=htable.contains("C");

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

The code above generates the following result.