How can I Use Collectors to collect in a ConcurrentHashMap instread of putting manually into ConcurrentHashMap
ConcurrentHashMap config
You can use Collectors.toConcurrentMap
results.stream()
.flatMap(res -> res.getSeries().stream())
.flatMap(series -> series.getValues().stream())
.collect(Collectors.toConcurrentMap(
vals -> vals.get(1).toString(),
vals -> vals.get(2).toString()));
We can do this as follows also:
results.stream()
.flatMap(res -> res.getSeries().stream())
.flatMap(series -> series.getValues().stream())
.collect(Collectors.toMap(
vals -> vals.get(1).toString(),
vals -> vals.get(2).toString(),
(vals1,vals2) -> vals2,
ConcurrentHashMap::new);