最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java8中Stream流求最大值最小值的實現(xiàn)示例

 更新時間:2023年04月25日 11:06:14   作者:Archie_java  
本文主要介紹了Java8中Stream流求最大值最小值的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

一、BigDecimal 求最大值和最小值

1. stream().reduce()實現(xiàn)

List<BigDecimal> list = new ArrayList<>(Arrays.asList(new BigDecimal("1"), new BigDecimal("2")));
BigDecimal max = list.stream().reduce(list.get(0), BigDecimal::max);
BigDecimal min = list.stream().reduce(list.get(0), BigDecimal::min);

2. stream().max()或stream().min()實現(xiàn)

List<BigDecimal> list = new ArrayList<>(Arrays.asList(new BigDecimal("1"), new BigDecimal("2")));
BigDecimal max = list.stream().max(Comparator.comparing(x -> x)).orElse(null);
BigDecimal min = list.stream().min(Comparator.comparing(x -> x)).orElse(null);

二、Integer 求最大值和最小值

1. stream().reduce()實現(xiàn)

List<Integer> list = new ArrayList<>(Arrays.asList(1, 2));
Integer max = list.stream().reduce(list.get(0), Integer::max);
Integer min = list.stream().reduce(list.get(0), Integer::min);

2. Collectors.summarizingInt()實現(xiàn)

List<Integer> list = new ArrayList<>(Arrays.asList(1, 2));
IntSummaryStatistics intSummaryStatistics = list.stream().collect(Collectors.summarizingInt(x -> x));
Integer max = intSummaryStatistics.getMax();
Integer min = intSummaryStatistics.getMin();

3. stream().max()或stream().min()實現(xiàn)

List<Integer> list = new ArrayList<>(Arrays.asList(1, 2));
Integer max = list.stream().max(Comparator.comparing(x -> x)).orElse(null);
Integer min = list.stream().min(Comparator.comparing(x -> x)).orElse(null);

三、Long 求最大值和最小值

1. stream().reduce()實現(xiàn)

List<Long> list = new ArrayList<>(Arrays.asList(1L, 2L));
Long max = list.stream().reduce(list.get(0), Long::max);
Long min = list.stream().reduce(list.get(0), Long::min);

2. Collectors.summarizingLong()實現(xiàn)

List<Long> list = new ArrayList<>(Arrays.asList(1L, 2L));
LongSummaryStatistics summaryStatistics = list.stream().collect(Collectors.summarizingLong(x -> x));
Long max = summaryStatistics.getMax();
Long min = summaryStatistics.getMin();

3. stream().max()或stream().min()實現(xiàn)

List<Long> list = new ArrayList<>(Arrays.asList(1L, 2L));
Long max = list.stream().max(Comparator.comparing(x -> x)).orElse(null);
Long min = list.stream().min(Comparator.comparing(x -> x)).orElse(null);

四、Double 求最大值和最小值

1. stream().reduce()實現(xiàn)

List<Double> list = new ArrayList<>(Arrays.asList(1d, 2d));
Double max = list.stream().reduce(list.get(0), Double::max);
Double min = list.stream().reduce(list.get(0), Double::min);

2. Collectors.summarizingLong()實現(xiàn)

List<Double> list = new ArrayList<>(Arrays.asList(1d, 2d));
DoubleSummaryStatistics summaryStatistics = list.stream().collect(Collectors.summarizingDouble(x -> x));
Double max = summaryStatistics.getMax();
Double min = summaryStatistics.getMin();

3. stream().max()或stream().min()實現(xiàn)

List<Double> list = new ArrayList<>(Arrays.asList(1d, 2d));
Double max = list.stream().max(Comparator.comparing(x -> x)).orElse(null);
Double min = list.stream().min(Comparator.comparing(x -> x)).orElse(null);

到此這篇關于Java8中Stream流求最大值最小值的實現(xiàn)示例的文章就介紹到這了,更多相關Java8 Stream流求最大值最小值內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • List對象去重和按照某個字段排序的實現(xiàn)方法

    List對象去重和按照某個字段排序的實現(xiàn)方法

    下面小編就為大家?guī)硪黄狶ist對象去重和按照某個字段排序的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-05-05
  • spring boot idea maven依賴找不到問題處理方法

    spring boot idea maven依賴找不到問題處理方法

    這篇文章主要介紹了spring boot idea 偶爾maven依賴找不到問題,這里總結了幾種處理方法,方便嘗試排查,對spring boot idea  maven依賴找不到問題感興趣的朋友跟隨小編一起看看吧
    2023-08-08
  • 懶人 IDEA 插件推薦: EasyCode 一鍵幫你生成所需代碼(Easycode用法)

    懶人 IDEA 插件推薦: EasyCode 一鍵幫你生成所需代碼(Easycode用法)

    這篇文章主要介紹了懶人 IDEA 插件推薦: EasyCode 一鍵幫你生成所需代碼,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-08-08
  • 詳解IDEA啟動多個微服務的配置方法

    詳解IDEA啟動多個微服務的配置方法

    這篇文章主要介紹了詳解IDEA啟動多個微服務的配置方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-01-01
  • HashMap和Hashtable的詳細比較

    HashMap和Hashtable的詳細比較

    這篇文章主要介紹了HashMap和Hashtable的詳細比較的相關資料,需要的朋友可以參考下
    2017-04-04
  • SpringBoot 版本兼容性問題解決

    SpringBoot 版本兼容性問題解決

    本文詳細介紹了SpringBoot版本兼容性問題的常見場景,包括與SpringFramework、依賴庫、JDK、SpringCloud及插件及工具的兼容性問題,幫助開發(fā)者避免兼容性問題,確保項目的穩(wěn)定性和可維護性
    2024-10-10
  • SpringBoot開發(fā)案例 分布式集群共享Session詳解

    SpringBoot開發(fā)案例 分布式集群共享Session詳解

    這篇文章主要介紹了SpringBoot開發(fā)案例 分布式集群共享Session詳解,在分布式系統(tǒng)中,為了提升系統(tǒng)性能,通常會對單體項目進行拆分,分解成多個基于功能的微服務,可能還會對單個微服務進行水平擴展,保證服務高可用,需要的朋友可以參考下
    2019-07-07
  • java實現(xiàn)門禁系統(tǒng)

    java實現(xiàn)門禁系統(tǒng)

    這篇文章主要為大家詳細介紹了java實現(xiàn)門禁系統(tǒng)的實現(xiàn)方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-01-01
  • Java文件操作類 File實現(xiàn)代碼

    Java文件操作類 File實現(xiàn)代碼

    這篇文章主要介紹了Java文件操作類 File實現(xiàn)代碼,需要的朋友可以參考下
    2017-08-08
  • JavaWeb中的常用的請求傳參注解說明

    JavaWeb中的常用的請求傳參注解說明

    這篇文章主要介紹了JavaWeb中的常用的請求傳參注解說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-04-04

最新評論

巨野县| 建平县| 无为县| 富平县| 盐池县| 买车| 洪江市| 阳信县| 娄烦县| 华坪县| 荔浦县| 奇台县| 乌什县| 辽阳市| 平乐县| 乐业县| 长白| 偃师市| 长春市| 九江县| 定边县| 和硕县| 图片| 额尔古纳市| 凯里市| 尼木县| 商南县| 拉萨市| 囊谦县| 恭城| 专栏| 衡南县| 来凤县| 龙南县| 河间市| 邵东县| 广昌县| 滦平县| 广丰县| 涿州市| 齐河县|