c#与java Integer

对放入HashMap中的元素会自动拆箱。会把Integer转换成int基本数据类型。
HashMap<String, Integer> words = new HashMap<String, Integer>(1000);

public int get(String word){
return words.get(word); //如果word没找到,就抛出异常
}
修改get方法:
public int get(String word){
Integer freq = words.get(word);
if(freq==null) //需要判断空值
return 1;
return freq;
}

 



posted on 2012-06-08 17:28  雨渐渐  阅读(414)  评论(0编辑  收藏  举报

导航