HashtablenumberTable = new Hashtable (); numberTable.put("one", 1); numberTable.put("two", 2); numberTable.put("three", 3); if(numberTable.containsKey("two")){ System.out.println("Two is present in the Hashtable."); } else{ System.out.println("Two is not present in the Hashtable."); }
Two is present in the Hashtable.
import java.util.Hashtable; public class HashTableDemo { public static void main(String[] args) { HashtablesportTable = new Hashtable (); sportTable.put(1, "Cricket"); sportTable.put(2, "Football"); sportTable.put(3, "Tennis"); if(sportTable.containsKey(4)){ System.out.println("Badminton is present in the Hashtable."); } else{ System.out.println("Badminton is not present in the Hashtable."); } } }
Badminton is not present in the Hashtable.Package Library: The java.util Hashtable class is part of the Java SE Library.