nerdexam
Oracle

1Z0-819 · Question #88

Given: Integer[] intArray = {2, 1, 3, 4, 5}; List<Integer> list = new ArrayList<>(Arrays.asList(intArray)); list.parallelStream() .forEach(e -> System.out.print(e + " ")); Which are true? (Choose…

The correct answer is B. The program prints 1 4 2 3, but the order is unpredictable. See the full explanation below for the reasoning.

Question

Given: Integer[] intArray = {2, 1, 3, 4, 5}; List<Integer> list = new ArrayList<>(Arrays.asList(intArray)); list.parallelStream() .forEach(e -> System.out.print(e + " ")); Which are true? (Choose some.)

Options

  • AThe output will be exactly 2 1 3 4 5.
  • BThe program prints 1 4 2 3, but the order is unpredictable.
  • CReplacing forEach() with forEachOrdered(), the program prints 2 1 3 4 5, but the order is unpredictable.
  • DReplacing forEach() with forEachOrdered(), the program prints 1 2 3 4 5.
  • EReplacing forEach() with forEachOrdered(), the program prints 2 1 3 4 5.

How the community answered

(46 responses)
  • A
    15% (7)
  • B
    72% (33)
  • C
    2% (1)
  • D
    7% (3)
  • E
    4% (2)

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice