The new version of Concurrent Hash Map of jdk 8 has two new Methods.
computeIfAbsent
computeIfPresent
putIfAbs
I've used computeIfPresent as a null-safe way to fetch lowercase values from a map of strings.
String s = fields.computeIfPresent("foo", (k,v) -> v.toLowerCase())
Before computeIfPresent was available I'd have to do this:
String s = map.get("foo");
if (s != null) {
s = s.toLowerCase();
}
Or this:
String s = map.containsKey("foo") ? map.get("foo").toLowerCase() : null;