Using Java 8 stream methods to get a max value

前端 未结 5 1286
暖寄归人
暖寄归人 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:53

    using Comparator:

    int max2 = arrRound.stream()
                .flatMap(round -> round.getHits().stream())
                .max(Comparator.comparing(Hits::getPrizeAmount))
                .map(Hits::getPrizeAmount)
                .orElse(-1);
    

提交回复
热议问题