Hashtable不仅像Vector一样可以动态存储一系列的对象,还能对存储的对象(称为值)都要安排另一个对象(称为关键字)与之关联。
--注:Hashtable中不能有重复的关键字。
在Hashtable中检索对象时,用作关键字的类必须覆盖 Object.hashCode()和Object.eauals()两个方法。
下面这个示例创建了一个数字的哈希表。它将数字的名称用作键:
Hashtable numbers = new Hashtable();
numbers.put("one", new Integer(1));
numbers.put("two", new Integer(2));
numbers.put("three", new Integer(3));