Given the code fragment:
What is the result?
Given the code fragment:
What is the result?
The code uses parallelStream, which means the order of execution for the reduce operation is not guaranteed to be sequential. This could lead to the string concatenation happening in any order, producing different results. Consequently, the program might print either 'Java EEJava SE' or 'Java SEJava EE'.
tested is D
D,tested
If we test the code with stream(),not parallelStream(),answer is B.
B and D are both possibilities... "Java" is not a true identity so can give unexpected results, but due to encounter order, will always be EE before SE...
Answer is D. Tested.
Answer D
D, tested public static void main(String[] args) { List<String> nums = Arrays.asList("EE", "SE"); String ans = nums.parallelStream().reduce("Java", (a, b) -> a.concat(b)); System.out.println(ans); }
Because it's parallelStream,