Implementation
Implement the Parallel Stats project with parallel streams to calculate summary statistics.
Intro
Time to implement Parallel Stats: use parallel streams to calculate sum, average, min, and max.
Code: sum
Use mapToInt().sum() on a parallel stream to calculate totals.
import java.util.*;public class Main {
public static void main(String[] args) {
List<Integer> nums = Arrays.asList(1,2,3,4,5,6,7,8,9,10);
int sum = nums.parallelStream().mapToInt(n -> n).sum();
System.out.println("Sum = " + sum);
}
}
All lessons in this course
- Design
- Implementation
- Benchmarks