nerdexam
Oracle

1Z0-819 · Question #82

Given int arr[][] = {{5,10},{8,12},{9,3}}; long count = Stream.of(arr) .flatMapToInt(IntStream::of) .map(n -> n + 1) .filter(n -> (n % 2 == 0)) .peek(System.out::print) .count()…

The correct answer is D. 6104 3. Option D is correct because the pipeline processes the flattened array [5,10,8,12,9,3] through three transformations before printing: map(n -> n+1) produces [6,11,9,13,10,4], then filter(n % 2 == 0) keeps only [6,10,4], and peek prints only those three surviving elements…

Working with Streams and Lambda Expressions

Question

Given int arr[][] = {{5,10},{8,12},{9,3}}; long count = Stream.of(arr) .flatMapToInt(IntStream::of) .map(n -> n + 1) .filter(n -> (n % 2 == 0)) .peek(System.out::print) .count(); System.out.println("\n" + count); What is the result?

Options

  • A6910103 7
  • B10126 3
  • C10126 7
  • D6104 3

How the community answered

(35 responses)
  • A
    6% (2)
  • B
    3% (1)
  • C
    11% (4)
  • D
    80% (28)

Explanation

Option D is correct because the pipeline processes the flattened array [5,10,8,12,9,3] through three transformations before printing: map(n -> n+1) produces [6,11,9,13,10,4], then filter(n % 2 == 0) keeps only [6,10,4], and peek prints only those three surviving elements consecutively - outputting 6104 - followed by count() returning 3.

Options A and C are wrong because their count of 7 is impossible: there are only 6 total elements, and count() tallies what passes through the filter, giving 3, not 7. Options B and C both show 10126, which would require the even elements to appear in a different order or set - a mistake likely made by applying the filter to the original values (10, 8, 12) instead of the mapped values (+1), or by misreading the order of stream operations.

Memory tip: In a stream pipeline, think left-to-right order matters - peek sits after filter, so it only sees elements that already survived. The count() terminal operation counts just those same survivors.

Topics

#flatMapToInt#stream pipeline#filter#map

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice