1z0-809 Exam QuestionsBrowse all questions from this exam

1z0-809 Exam - Question 198


Given the code fragment:

What is the result?

Show Answer
Correct Answer: BC

The code snippet uses `parallelStream()` to print the elements in a potentially non-deterministic order. The first call to `parallelStream().forEach(s -> System.out.print(s));` can output the elements in any order since parallel streams do not guarantee any specific order. The second call to `parallelStream().forEachOrdered(s1 -> System.out.print(s1));` ensures that the elements are printed in their encounter order (the order in which they appear in the list). Given the list order is B, C, A, D, the two sections will output a random order of the elements followed by BCAD in the encounter order. Therefore, the correct answer is BCAD after some random order output.

Discussion

6 comments
Sign in to comment
Svetleto13Option: C
May 21, 2021

The answer is ADCB BCAD.So,it should be C if we change the answer to this.

jduarteOption: C
Jan 29, 2021

Answer C. tested

WilsonKKerllOption: C
Mar 21, 2022

Answer is C.

duydnOption: C
Sep 22, 2023

C is correct

steefaandOption: C
Feb 7, 2024

C is correct.

DarGrinOption: C
Jun 6, 2024

Answer is C. ACDB (in random order) B C A D