Page 1 of 1
About Question enthuware.ocpjp.v11.2.3326 :
Posted: Wed Apr 14, 2021 8:40 am
by maria_maria
Code: Select all
Character[] ca = {'b', 'c', 'a', 'e', 'd'};
List<Character> l = Arrays.asList(ca);
l.parallelStream().peek(System.out::print).forEachOrdered(System.out::print);
The correct answer from the test is :
The characters printed by peek may be in any order but the characters printed by forEachOrdered will always be in the same order as the original list i.e. bcaed. but I have run it with IntelliJ and one result that I got was
cebbcdaaed.
Is my IDE going bonkers?
Re: About Question enthuware.ocpjp.v11.2.3326 :
Posted: Wed Apr 14, 2021 8:48 am
by admin
No, you are interpreting the results incorrectly. The output of peek and forEachOrdered is interspersed. Run the code without peek and then observe the output.
Re: About Question enthuware.ocpjp.v11.2.3326 :
Posted: Wed Apr 14, 2021 8:57 am
by maria_maria
Indeed it's bcaed.
I thought the result after running the code should be something like .....bcaed (where ..... is a combination of 'b', 'c', 'a', 'e', 'd').
You mean the result I got cebbcdaaed contains in fact the sequence bcaed but between the other characters from peek?
Re: About Question enthuware.ocpjp.v11.2.3326 :
Posted: Wed Apr 14, 2021 9:31 am
by admin
that's correct.
Re: About Question enthuware.ocpjp.v11.2.3326 :
Posted: Wed Apr 14, 2021 9:33 am
by maria_maria
Thank you very much!