java哈希表指定的key对应的value值自加1实例,最近项目中要用到哈希表,其中key为String型,value为int型。我需要将查找到的key对应的value值自加1,最后实现的代码如下:
private void hashTableValuePlusOne(Hashtable ht, String str)
{
int n = Integer.parseInt(ht.get(str).toString());
//ht.remove(str);
ht.put(str, ++n); //不用前面的删除语句,put函数会自动覆盖
}
本文链接地址: java哈希表指定的key对应的value值自加1实例