Sunil Kumar Naik Sunil Kumar Naik - 8 months ago 53
Java Question

How can I use Collectors instead of manually putting into ConcurrentHashMap in java 8

How can I Use Collectors to collect in a ConcurrentHashMap instread of putting manually into ConcurrentHashMap

ConcurrentHashMap<String, String> configurationMap = new ConcurrentHashMap<>();
List<Result> results = result.getResults(); -> {
res.getSeries().stream().forEach(series -> {
series.getValues().stream().forEach(vals ->{

//Note: vals is List<List<Object>> type

Help will be appreciated.


You can use Collectors.toConcurrentMap
           .flatMap(res -> res.getSeries().stream())
           .flatMap(series -> series.getValues().stream())
                                  vals -> vals.get(1).toString(),
                                  vals -> vals.get(2).toString()));