nerdexam
Oracle

1Z0-819 · Question #192

Given: List<Integer> numbers = List.of(5, 3, 0, 8, 1, 9, 5, 7, 6, 4); int sum = numbers.stream().reduce(0, (n, m) -> n + m); // line 1 You want to make the reduction operation parallelized. Which…

The correct answer is A. Replace line 1 with int sum = numbers. stream (). Interate (). (a -> a+1. Reduce (0, (n,m) -> n+m). See the full explanation below for the reasoning.

Question

Given: List<Integer> numbers = List.of(5, 3, 0, 8, 1, 9, 5, 7, 6, 4); int sum = numbers.stream().reduce(0, (n, m) -> n + m); // line 1 You want to make the reduction operation parallelized. Which two modifications should you make?

Options

  • AReplace line 1 with int sum = numbers. stream (). Interate (). (a -> a+1. Reduce (0, (n,m) -> n+m);
  • BReplace line 1with int sum = numbers. ParallelStream (). Reduce (0, (n,m) -> n+m);
  • CReplace line 1with int sum = numbers. stream (). mapToInt (a -> a.Reduce (0, (n,m) -> n+m);
  • DReplace line 1with int sum = number. stream (). flatMap (a -> a).reduce (0, (n,m) -> n+m);
  • EReplace line 1with int sum = number.stream. parallel (). Reduce (0, (n,m) -> n+m);

How the community answered

(31 responses)
  • A
    81% (25)
  • C
    6% (2)
  • D
    10% (3)
  • E
    3% (1)

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice