1Z0-809 : About enthuware.ocpjp.v8.2.1773

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

Moderator: admin

Post Reply
stefanbanu
Posts: 3
Joined: Sun Mar 04, 2018 1:09 am
Contact:

1Z0-809 : About enthuware.ocpjp.v8.2.1773

Post by stefanbanu »

hi,

I got a question:

Given:
List<String> l1 = Arrays.asList("a", "b");
List<String> l2 = Arrays.asList("1", "2");

Which of the following lines of code will print the following values?
a
b
1
2

The correct answer is this one: Stream.of(l1, l2).flatMap((x)->x.stream()).forEach((x)->System.out.println(x));

but when I tried on my ide I'm still getting this result:
[a, b]
[1, 2]

the result that is the same as this one: Stream.of(l1, l2).forEach((x)->System.out.println(x));
[a, b]
[1, 2]
which I choose in first place.

so, what is the correct answer in the end?

thank you,
Stefan
Last edited by admin on Sun Mar 04, 2018 8:30 am, edited 1 time in total.
Reason: added qid in subject

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

Re: 1Z0-809

Post by admin »

Well, as you have mentioned, the output of options 1 and 2 is not what the question is asking about. Option 3, which is set as the right option produces the required output -
a
b
1
2
This is also explained in the explanation.

HTH,
Paul.

stefanbanu
Posts: 3
Joined: Sun Mar 04, 2018 1:09 am
Contact:

Re: 1Z0-809 : About enthuware.ocpjp.v8.2.1773

Post by stefanbanu »

thank you :)

sir_Anduin@yahoo.de
Posts: 62
Joined: Fri Aug 07, 2015 2:16 pm
Contact:

Re: 1Z0-809 : About enthuware.ocpjp.v8.2.1773

Post by sir_Anduin@yahoo.de »

in answer 3 (Stream.of(l1, l2).flatMap((x)->Stream.of(x)).forEach((x)->System.out.println(x));)
Stream.of(x) will create a stream of List<String>, but wenn need a stream of String

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests