| /home/oracle/labs/06CollectionOperations/examples/EmployeeSearch/src/com/example/lambda/A12CollectMath.java |
1 package com.example.lambda;
2
3 import java.util.ArrayList;
4 import java.util.Comparator;
5 import java.util.List;
6 import java.util.stream.Collectors;
7
8
9
10 @author
11
12 public class A12CollectMath {
13
14 public static void main(String[] args) {
15
16 List<Employee> eList = Employee.createShortList();
17
18
19 double avgSalary = eList.stream()
20 .filter(e -> e.getRole().equals(Role.EXECUTIVE))
21 .filter(e -> e.getState().equals("CO"))
22 .collect(
23 Collectors.averagingDouble(Employee::getSalary));
24
25 System.out.println("\n== CO Exec Avg Salary ==");
26 System.out.printf("Average: $%,9.2f %n", avgSalary);
27
28 }
29
30 }
31