.mapToObj(e –> e + “”).reduce((e1, e2) –> e1 + ” ” + e2).get());
a. nothing
b. 1
c. 2
d. 3
e. 1 2 3 4 5
#
34. Show the output of the following code:
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class Test {
public static void main(String [] args){
int[][] m = {{1, 2, 3}, {3, 4, 5}, {5, 2}, {1, 3}};
Stream.of(m).map(e –> IntStream.of(e))
.reduce((e1, e2) –> IntStream.concat(e1, e2))
.get().distinct()
.forEach(e –> System.out.print(e + ” “));
}
}
a. 1 2 3 3 4 5 5 2 1 2
b. 1 2 3 4 5
c. 1 2 3 4 5 in a random order
d. 5 4 3 2 1
#
35. Show the output of the following code:
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class Test {
public static void main(String [] args){
int[][] m = {{1, 2, 3}, {3, 4, 5}, {5, 2}, {1, 3}};
System.out.println(
Stream.of(m).map(e –> IntStream.of(e))
.reduce((e1, e2) –> IntStream.concat(e1, e2))
.get().distinct().mapToObj(e –> e + “”)
.reduce((e1, e2) –> e1 + “, ” + e2).get());
}
}
a. 1, 2, 3, 3, 4, 5, 5, 2, 1, 2
b. 1, 2, 3, 3, 4, 5, 5, 2, 1, 2,
c. 1, 2, 3, 4, 5,
#
Section 30.6 Stream Reduction Using the collect Method
36. The following statement displays .