About Question enthuware.ocpjp.v11.2.3326 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
maria_maria
Posts: 10
Joined: Wed Mar 03, 2021 5:39 am
Contact:

About Question enthuware.ocpjp.v11.2.3326 :

Post 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?

admin
Site Admin
Posts: 10058
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v11.2.3326 :

Post 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.
If you like our products and services, please help us by posting your review here.

maria_maria
Posts: 10
Joined: Wed Mar 03, 2021 5:39 am
Contact:

Re: About Question enthuware.ocpjp.v11.2.3326 :

Post 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?

admin
Site Admin
Posts: 10058
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v11.2.3326 :

Post by admin »

that's correct.
If you like our products and services, please help us by posting your review here.

maria_maria
Posts: 10
Joined: Wed Mar 03, 2021 5:39 am
Contact:

Re: About Question enthuware.ocpjp.v11.2.3326 :

Post by maria_maria »

Thank you very much!

Post Reply

Who is online

Users browsing this forum: No registered users and 119 guests