标签:final ted lan package win utils cte bsp 视频
裁减计算
视频讲解: https://www.bilibili.com/video/av77715582/
EmployeeTest.java
package com.example.demo; import lombok.extern.log4j.Log4j2; import org.junit.Test; import javax.swing.plaf.basic.BasicTreeUI; import java.util.*; import java.util.stream.Collector; import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @Log4j2 public class EmployeeTest extends BaseTestCase { @Test public void reduce(){ double dSum = list.stream().map(Employee::getSalary).reduce(Double::sum).get(); assertTrue(dSum == 8000); double dSum2 = list.stream().map(Employee::getSalary).reduce((a,b) ->a + b).get(); assertTrue(dSum == dSum2); double dSum3 = list.stream().map(Employee::getSalary).reduce((a,b) ->{ System.out.println("a:"+a+" b"+b); return a + b; }).get(); assertTrue(dSum == dSum3); double dSum4 = list.stream().map(Employee::getSalary).reduce(AddUtils::add).get(); assertTrue(dSum == dSum4); double dSum5 = list.stream().map(Employee::getSalary).reduce(0.00,Double::sum); assertTrue(dSum == dSum5); } static class AddUtils { public static Double add(Double a, Double b) { return a + b; } } }
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分钟学习
标签:final ted lan package win utils cte bsp 视频
原文地址:https://www.cnblogs.com/JavaWeiBianCheng/p/11967294.html