Given the code fragment:
Which two code fragments, independently, replace line 1 to implement the equivalent reduce operation? (Choose two.)
Given the code fragment:
Which two code fragments, independently, replace line 1 to implement the equivalent reduce operation? (Choose two.)
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.
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
B, D AND E, ARE VALIDS. PARALLELL is valid in intstraeam()
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
Tested, D and E
Tested
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