Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 165

Given the code fragment:

Which two code fragments, independently, replace line 1 to implement the equivalent reduce operation? (Choose two.)

    Correct Answer: D, E

    The correct options are those that replace the code fragment using the reduce operation properly. Option D correctly performs a parallel reduction on an IntStream and returns an OptionalInt, which is then converted to an Integer. Option E performs a reduction directly on the IntStream returning an int. Both approaches are valid to replace the original line 1 operation using reduce to sum the elements of the stream.

Discussion
ASPushkinOptions: DE

answer: DE A. not possible output is Optional B. - wrong output must int C. - wrong in reduce accumulator should have two parameters D. E. - correct

d7bb0b2Options: BD

B, D AND E, ARE VALIDS. PARALLELL is valid in intstraeam()

d7bb0b2

SORRY : corrected D and E are correct, B is not valid reduce with acumulator parameter(first parameters before lambda) return an int NO optional int

dillemanOptions: DE

Tested, D and E

Ashan_OzlovOptions: DE

Tested

[Removed]Options: DE

Apparently the overloaded reduce method on an IntStream accepting an identifier as the first parameter, will return an INT. Whenever you use the one without an identifier it returns an OptionalInt