/home/oracle/labs/07ParallelStreams/examples/EmployeeSearch/src/com/example/lambda/A05AvoidStateful.java
 1 package com.example.lambda;
 2 
 3 import java.util.ArrayList;
 4 import java.util.List;
 5 import java.util.stream.Collectors;
 6 
 7 /**
 8  *
 9  * @author oracle
10  */
11 public class A05AvoidStateful {
12 
13     public static void main(String[] args) {
14         
15         List<Employee> eList = Employee.createShortList();
16         List<Employee> newList01 = new ArrayList<>();
17         List<Employee> newList02 = new ArrayList<>();
18         
19         eList.stream() // Not Parallel. Bad.
20             .filter(e -> e.getDept().equals("Eng"))
21             .forEach(e -> newList01.add(e)); 
22 
23         newList02 = eList.stream() // Good Parallel
24             .filter(e -> e.getDept().equals("Eng"))
25             .collect(Collectors.toList());
26         
27     }
28 }
29