Non-determinism in parallel streams, the elements are partitioned into smaller sub-streams, and the reduction is performed on each sub-stream independently. it's possible that the 5 (initial value provided to reduce()) is added to some elements before they are added to others.
// D.
int sum = listOfNumbers.parallelStream().reduce(5, Integer::sum);
// (1 + 5) + (2 + 5) + (3 + 5) + (4 + 5) + (5 + 5) + (6 + 5) + (7 + 5) + (8 + 5) + (9 + 5) + (10 + 5) = 105
System.out.println(">>> sum = " + sum);
// >>> sum = 105
A, B, C, E return sum = 60.
upvoted 2 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
SrinivasJasti
2 weeks, 3 days agoxplorerpj
6 months, 3 weeks agoSamps
8 months agoc6437d5
9 months, 3 weeks agojames2033
10 months, 4 weeks ago