简体   繁体   English

JAVA-无法添加到HashMap

[英]JAVA - Can't add to HashMap

I am very new to JAVA and I wrote this code: 我是JAVA的新手,我写了这段代码:

Map<String,Integer> map = new HashMap<String,Integer>();
map.add("Key",13);

Why is it giving the error on eclipse: 为什么它会在eclipse上给出错误:

The method add(String, int) is undefined for the type Map<String,Integer>

There is no add method. 没有add方法。 The method you want is put . 您想要的方法被put

map.put("Key", 13);

See the Javadocs here: http://docs.oracle.com/javase/6/docs/api/java/util/HashMap.html#put(K , V) 在这里查看Javadocs: http//docs.oracle.com/javase/6/docs/api/java/util/HashMap.html#put(K ,V)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM