Java Code Examples for java.util.Hashtable.contains()

The following are Jave code examples for showing how to use contains() of the java.util.Hashtable class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: javaide   File: CheckValueOfHashtableExample.java   View Source Code Vote up 6 votes
public static void main(String[] args) {

    //create Hashtable object
    Hashtable ht = new Hashtable();

    //add key value pairs to Hashtable
    ht.put("1", "One");
    ht.put("2", "Two");
    ht.put("3", "Three");

    /*
      To check whether a particular value exists in Hashtable use
      boolean contains(Object key) method of Hashtable class.
      It returns true if the value is mapped to one or more keys in the
      Hashtable otherwise false.
    */

    boolean blnExists = ht.contains("Two");
    System.out.println("Two exists in Hashtable ? : " + blnExists);
  }