我已经创建了一个哈希表,我正在尝试使用枚举来打印出键和值。当我尝试编译代码时,我不断收到一个编译时错误,说我需要在新的双精度中放入一个“[”,我已经放入哈希表中。
编译前:toys.put("Race Car", new double (29.99));
编译时错误说我需要这样放置:
Toys.put("Race Car", new double [29.99]);
我究竟做错了什么?
public static void main(String[] args) {
Hashtable toys = new Hashtable();
Enumeration toyName;
String getToyName;
double priceOfToy;
toys.put("Race Car", new double(29.99));
toys.put("Toy Bear", new double(15.99));
toys.put("Action Figure", new double(9.99));
//Show prices of each toy
toyName = toys.keys();
//Uses hasMoreElements method from enumeration to check what is in the hashtable
while (toyName.hasMoreElements()) {
//uses nextElement method from enumeration interface to
getToyName = (String) toyName.nextElement();
System.out.println(getToyName + "is now priced at " + toys.get(getToyName));
}
}