java8的lambda求map最大值的五种方法

时间:2025-04-21 08:04:31

 

Map<String,Integer> map = new HashMap<>();
        ("1", 1);
        ("2", 2);
        ("3", 3);
        //第一种方法
        Optional<<String, Integer>> max0 = ()
                .stream()
                .max(());
        //第二种方法
        Optional<<String, Integer>> max1 = ()
                .stream().max((x1, x2) -> ((), ()));

        //第三种方法
        Optional<<String, Integer>> max3 = ()
                .stream()
                .collect((()));

        //第四种方法
        Optional<<String, Integer>> max4 = ()
                .stream()
                .max((::getValue));

        //第五种方法
        IntSummaryStatistics max5 = ()
                .stream()
                .collect((::getValue));