how to find maximum value from a Integer using stream in java 8?

后端 未结 8 981
无人及你
无人及你 2020-12-23 00:26

I have a list of Integer list and from the list.stream() I want the maximum value. What is the simplest way? Do I need comparator?

8条回答
  •  死守一世寂寞
    2020-12-23 00:53

    Another version could be:

    int maxUsingCollectorsReduce = list.stream().collect(Collectors.reducing(Integer::max)).get();
    

提交回复
热议问题