日期:2014-05-20  浏览次数:20697 次

怎样取出并修改HashMap中的值
HashMap<String, Integer> hm=new HashMap<String, Integer>();
int i=hm.get("abc");
i++;

这样并不能修改"abc"对应的值,有什么办法吗
java? hashmap

------解决方案--------------------
引用:
HashMap<String, Integer> hm=new HashMap<String, Integer>();
int i=hm.get("abc");
i++;

这样并不能修改"abc"对应的值,有什么办法吗


直接覆盖就行,使用put(key,value)方法覆盖
------解决方案--------------------
HashMap<String, Integer> hm=new HashMap<String, Integer>();
int i=hm.get("abc");
hm.put("abc",i++);