Professional Documents
Culture Documents
Import java.util.Hashtable;
public class myClass
{
public statics void main(String[] args)
{
// to 1 i tng Hashtable
Hashtable ht = new Hashtable();
// thm vo 2 gi tr Key v Value ti Hashtable
ht.put("1","one");
ht.put.("2","two");
ht.put.("3","three");
// removed all the Hashtable
/*ht.clear();
System.out.println("Total key value pairs in Hashtable are : " + ht.size());
*/
/*
/*
removed key value trong Hashtable s dng phng thc
Object remove(Object key) of Hashtable class.
*/
Object obj = ht.remove("2");
System.out.println(obj + " Removed from Hashtable");
Enumeration e = ht.elements();
while(e.hasMoreElements())
System.out.println(e.nextElement());
*/
// kim tra xem gi tr ca 1 Key c tn ti trong Hashtable khng
// s dng phng thc boolean containsKey(Object key) ca lp hashtable
// n s tr v true nu Hashtable cha key v ngc li
boolean blnExists = ht.containsKey("2");
System.out.println("2 c tn ti trong hashtable ?:"+blnExists);
/* 2 c tn ti trong Hashtable ? :true
}
}