2

我对 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>
4

1 回答 1

7

没有add方法。你想要的方法是put

map.put("Key", 13);

在此处查看 Javadocs:http ://docs.oracle.com/javase/6/docs/api/java/util/HashMap.html#put(K , V)

于 2013-08-29T23:45:39.767 回答