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

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

    int max = list.stream().reduce(Integer.MIN_VALUE, (a, b) -> Integer.max(a, b));
    

提交回复
热议问题