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
1Z0-809 : About enthuware.ocpjp.v8.2.1773
Moderator: admin
-
- Posts: 3
- Joined: Sun Mar 04, 2018 1:09 am
- Contact:
1Z0-809 : About enthuware.ocpjp.v8.2.1773
Last edited by admin on Sun Mar 04, 2018 8:30 am, edited 1 time in total.
Reason: added qid in subject
Reason: added qid in subject
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: 1Z0-809
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.
a
b
1
2
This is also explained in the explanation.
HTH,
Paul.
-
- Posts: 3
- Joined: Sun Mar 04, 2018 1:09 am
- Contact:
-
- Posts: 62
- Joined: Fri Aug 07, 2015 2:16 pm
- Contact:
Re: 1Z0-809 : About enthuware.ocpjp.v8.2.1773
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
Stream.of(x) will create a stream of List<String>, but wenn need a stream of String
Who is online
Users browsing this forum: No registered users and 12 guests