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

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

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

一、BigDecimal 求最大值和最小值

1. stream().reduce()實(shí)現(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()實(shí)現(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()實(shí)現(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()實(shí)現(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()實(shí)現(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()實(shí)現(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()實(shí)現(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()實(shí)現(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()實(shí)現(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()實(shí)現(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()實(shí)現(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);

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

相關(guān)文章

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

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

    下面小編就為大家?guī)?lái)一篇List對(duì)象去重和按照某個(gè)字段排序的實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-05-05
  • spring boot idea maven依賴(lài)找不到問(wèn)題處理方法

    spring boot idea maven依賴(lài)找不到問(wèn)題處理方法

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

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

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

    詳解IDEA啟動(dòng)多個(gè)微服務(wù)的配置方法

    這篇文章主要介紹了詳解IDEA啟動(dòng)多個(gè)微服務(wù)的配置方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-01-01
  • HashMap和Hashtable的詳細(xì)比較

    HashMap和Hashtable的詳細(xì)比較

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

    SpringBoot 版本兼容性問(wèn)題解決

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

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

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

    java實(shí)現(xiàn)門(mén)禁系統(tǒng)

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

    Java文件操作類(lèi) File實(shí)現(xiàn)代碼

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

    JavaWeb中的常用的請(qǐng)求傳參注解說(shuō)明

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

最新評(píng)論

湖州市| 长宁县| 河南省| 潮州市| 内黄县| 横山县| 慈溪市| 沙雅县| 洛宁县| 桑日县| 响水县| 永州市| 澄迈县| 城步| 博兴县| 成武县| 闽侯县| 洪泽县| 寻乌县| 建湖县| 大城县| 岳阳县| 铁力市| 西安市| 临高县| 晋城| 眉山市| 南汇区| 神木县| 崇义县| 始兴县| 奉贤区| 漯河市| 淳化县| 石景山区| 蕉岭县| 保山市| 丰镇市| 丹东市| 庐江县| 高要市|