Question: The example of Fig. 17.7 summed the triples of the even integers from 2 through 10. We used filter and map in the stream pipeline
The example of Fig. 17.7 summed the triples of the even integers from 2 through 10. We used filter and map in the stream pipeline to demonstrate both in one stream pipeline. Reimplement Fig. 17.7’s stream pipeline using only map (similar to Fig. 17.4).
Fig. 17.7

Fig. 17.4

1 // Fig. 17.7: StreamFilterMapReduce.java 2 // Triple the even ints from 2 through 10 then sum them with IntStream. import java.util.stream. IntStream; 3 4 5 6 9 10 [1 12 13 public class StreamFilterMapReduce { public static void main(String[] args) { // sum the triples of the even integers from 2 through 10 System.out.printf( "Sum of the triples of the even ints from 2 through 10 is: %d%n", IntStream.rangeClosed (1, 10) .filter(x -> x % 2 == 0) .map(x -> x * 3) .sum()); 14 15 } } Sum of the triples of the even ints from 2 through 10 is: 90
Step by Step Solution
3.33 Rating (150 Votes )
There are 3 Steps involved in it
The question is asking to modify the stream pipeline from Figure 177 so that it no longer uses the f... View full answer
Get step-by-step solutions from verified subject matter experts
