/** * @author lautturi.com * Java example: java determine whether hashtable contains a key */ import java.util.*; import java.util.Map.Entry; public class Lautturi { public static void main(String[] args) { Hashtable<Integer,String> hash_tab=new Hashtable<Integer,String>(); hash_tab.put(5,"Apple"); hash_tab.put(7,"Banana"); hash_tab.put(12,"Cherry"); hash_tab.put(33,"Orange"); hash_tab.put(23,"Lautturi"); if(hash_tab.containsKey(33)) { System.out.println("The hash table contains the key 33"); } if(!hash_tab.containsKey(34)) { System.out.println("The hash table does not contain the key 34"); } } }
output:
The hash table contains the key 33 The hash table does not contain the key 34