Hashtable 不仅能像Vetor那样存取对象 还可以给每一个对象指定一个key
Key和值都不能是空
不能有重复的key
定义方法 Hashtable has = new Hashtable();
添加值has.put("a", new Integer(1));
获取值Integer intHas = (Integer)has.get("a");
遍历值Enumeration en = has.keys();
while(en.hasMoreElements()){
例子
public static void main(String[] args) {
Hashtable has = new Hashtable();
has.put("a", new Integer(1));
has.put("b", new Integer(2));
has.put("c", new Integer(3));
Integer intHas = (Integer)has.get("a");
//遍历key
Enumeration en = has.keys();
while(en.hasMoreElements()){
String key = (String)en.nextElement();
System.out.print(key+"=");
System.out.println(has.get(key));
}
}