方法都很简单, 不解释了. 如何用java8 的新api改为更优雅的 一行代码格式?
void addOne(Map<String, Integer> map,
String key,
int increment,
int defVal){
if(map.containsKey(key))
map.put(key, map.get(key) + increment);
else
map.put(key, defVal);
}
void addString(Map<String, Set<String>> map,
String key,
String val){
if(!map.containsKey(key))
map.put(key, new HashSet<>());
map.get(key).add(val);
}
It should be possible to use several tool methods provided by the Map interface, as follows: