Check if a particular key exists in Hashtable - Java Collection Framework

Java examples for Collection Framework:Hashtable

Description

Check if a particular key exists in Hashtable

Demo Code

 
import java.util.Hashtable;
 
public class Main {
  public static void main(String[] args) {
    Hashtable ht = new Hashtable();
   /*from ww  w  . j  a v  a 2s .c o  m*/
    ht.put("1","One");
    ht.put("2","Two");
    ht.put("3","Three");
   
    boolean blnExists = ht.containsKey("2");
    System.out.println("2 exists in Hashtable ? : " + blnExists);
  }
}

Result


Related Tutorials