首页 > 技术文章 > Stream系列(十一)SummarizingDouble方法使用

JavaWeiBianCheng 2019-12-04 13:13 原文

汇总

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

 

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分钟学习

 

 

推荐阅读