Using Java 8 stream methods to get a max value

前端 未结 5 1239
暖寄归人
暖寄归人 2021-01-22 00:00

I would like to get the max value out of a list using java 8 stream methods.

The structure is the following:

  • I read a csv file and store the data of every
5条回答
  •  情歌与酒
    2021-01-22 00:39

    Use flatMap:

    int maxPrize = arrRound.stream() // Stream
                           .flatMap(r -> r.getHits().stream()) // Stream
                           .mapToInt(Hit::getPrizeAmount) // IntStream
                           .max()
                           .orElse(0);
    

提交回复
热议问题