I am using concurrent hash map like this:
private final Map<String, List<FooObject>> map = new ConcurrentHashMap<>();
I am using List of my custom objects as value. When application started and I need store some object into List for specific key in map, I need at first check, if there are some value (List) for that key:
FooObject foo = new Foo(...);
if (map.get(key) == null) {
map.putIfAbsent(key, Lists.newArrayList(foo))
} else {
map.get(key).add(foo);
}
My question is if there are way to write code above more simpler? With some java 8 feature? I am also using guava and spring in project, so if there some utility in that frameworks it is still fine for me. Thanks.