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

后端 未结 8 957
无人及你
无人及你 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

    With stream and reduce

    Optional max = list.stream().reduce(Math::max);
    

提交回复
热议问题