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

后端 未结 2 1433
梦如初夏
梦如初夏 2021-01-12 19:48

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

ConcurrentHashMap config         


        
2条回答
  •  逝去的感伤
    2021-01-12 19:55

    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()));
    

提交回复
热议问题