exam questions

Exam 1z0-809 All Questions

View all questions & answers for the 1z0-809 exam

Exam 1z0-809 topic 1 question 3 discussion

Actual exam question from Oracle's 1z0-809
Question #: 3
Topic #: 1
[All 1z0-809 Questions]

Given the code fragment:
List<Integer> values = Arrays.asList (1, 2, 3);
values.stream ()
.map(n -> n*2) //line n1
.peek(System.out::print) //line n2
.count();
What is the result?

  • A. 246
  • B. The code produces no output.
  • C. A compilation error occurs at line n1.
  • D. A compilation error occurs at line n2.
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
speed045
Highly Voted 4 years, 1 month ago
In java 8, count() acts as a terminal operation. so values will be printed. In java 9 or above, output might not be printed as the jre can determine the number from stream directly without using peek() operation on elements.
upvoted 8 times
...
Ritesh_
Highly Voted 5 years, 3 months ago
Answer is A
upvoted 5 times
...
MPignaProTech
Most Recent 1 month, 4 weeks ago
no output from java 9 and more
upvoted 1 times
...
steefaand
11 months, 1 week ago
Selected Answer: A
Answer is A. Each element is doubled and printed with peek operation, while result of count operation is ignored.
upvoted 1 times
...
r1muka5
1 year, 10 months ago
The correct answer is A.
upvoted 1 times
...
karta
2 years, 1 month ago
Selected Answer: A
In java 8 answer is A In java 9 or more answer is B
upvoted 2 times
...
kishanrao
2 years, 5 months ago
The answer is B, output might not be printed
upvoted 1 times
...
WilsonKKerll
2 years, 10 months ago
A test.
upvoted 1 times
...
YasinGaber
2 years, 11 months ago
Please help, i typed the code as following but i'm not getting any output, what can be wrong?: package birdie; import java.util.Arrays; import java.util.List; class Vehicle { public static void main(String[] args) { List<Integer> values = Arrays.asList (1, 2, 3); values.stream () .map(n -> n*2) //line n1 .peek(System.out::print) //line n2 .count(); } }
upvoted 1 times
...
ayzo
3 years, 11 months ago
Yes the correct answer is 246, so A is the correct option.
upvoted 3 times
...
rameasy
4 years, 5 months ago
Ans: A
upvoted 4 times
...
M_Jawad
4 years, 12 months ago
The correct answer is B . when you use count() , you cant peak on the elements of the stream. The number of elements covered by the stream source, a List, isknown and the intermediate operation, peek, does not inject intoor remove elements from the stream (as may be the case for flatMap or filter operations). Thus the count is thesize of the List and there is no need to execute the pipelineand, as a side-effect, print out the list elements.
upvoted 2 times
Pasci
4 years, 7 months ago
no, Answer A is correct! copy paste the code into eclipse and be surprised ;-)
upvoted 2 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago