【发布时间】:2013-08-29 23:44:06
【问题描述】:
我是 JAVA 的新手,我写了这段代码:
Map<String,Integer> map = new HashMap<String,Integer>();
map.add("Key",13);
为什么会在eclipse上报错:
The method add(String, int) is undefined for the type Map<String,Integer>
【问题讨论】:
我是 JAVA 的新手,我写了这段代码:
Map<String,Integer> map = new HashMap<String,Integer>();
map.add("Key",13);
为什么会在eclipse上报错:
The method add(String, int) is undefined for the type Map<String,Integer>
【问题讨论】:
没有add 方法。你要的方法是put。
map.put("Key", 13);
在此处查看 Javadocs:http://docs.oracle.com/javase/6/docs/api/java/util/HashMap.html#put(K, V)
【讨论】: