汇总

视频讲解: https://www.bilibili.com/video/av78011675/

Stream系列(十一)SummarizingDouble方法使用

 

EmployeeTestCase.java
package com.example.demo;

import lombok.extern.log4j.Log4j2;
import org.junit.Test;

import java.util.DoubleSummaryStatistics;
import java.util.stream.Collectors;

@Log4j2
public class EmployeeTestCase extends BaseTestCase {
    @Test
    public void statis(){
        //实现方式一
        DoubleSummaryStatistics statistics = list.stream().collect(Collectors.summarizingDouble(Employee::getSalary));
        //实现方式二
        DoubleSummaryStatistics statistics1 = list.stream().mapToDouble(Employee::getSalary) .summaryStatistics();
    }
}
BaseTestCase.java
package com.example.demo;

import java.util.Arrays;
import java.util.List;

public class BaseTestCase {
    protected static final List<Employee> list = Arrays.asList(
            new Employee(1, "Alex", 1000),
            new Employee(2, "Michael", 2000),
            new Employee(3, "Jack", 1500),
            new Employee(4, "Owen", 1500),
            new Employee(5, "Denny", 2000));
}

 

关注公众号,坚持每天3分钟学习

Stream系列(十一)SummarizingDouble方法使用

 

 

相关文章:

  • 2022-01-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-01
  • 2021-11-23
  • 2021-06-01
猜你喜欢
  • 2022-12-23
  • 2019-12-09
  • 2019-12-05
  • 2022-12-23
  • 2022-12-23
  • 2019-11-30
  • 2019-12-02
相关资源
相似解决方案