exam questions

Exam 1z0-819 All Questions

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

Exam 1z0-819 topic 1 question 13 discussion

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

Why would you choose to use a peek operation instead of a forEach operation on a Stream?

  • A. to process the current item and return void
  • B. to remove an item from the end of the stream
  • C. to process the current item and return a stream
  • D. to remove an item from the beginning of the stream
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

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
ASPushkin
4 months ago
Selected Answer: C
The peek operation is an intermediate operation the forEach operation, is a terminal operation the processing order of Collection.stream().forEach() is undefined. so the forEach() is explicitly nondeterministic.
upvoted 1 times
...
Lebannin
1 year, 5 months ago
Selected Answer: C
C is the correct answer, and the explanation is as Stavok said.
upvoted 2 times
...
Stavok
1 year, 7 months ago
Selected Answer: C
C is the correct answer
upvoted 2 times
Stavok
1 year, 6 months ago
The peek operation is an intermediate operation that allows you to perform an action on each element of a stream as they are consumed from the resulting stream. Unlike the forEach operation, which is a terminal operation that consumes the entire stream and returns void, the peek operation returns a new stream that is identical to the original stream, with the additional side effect of the provided action.
upvoted 5 times
...
...
Ankit1010
1 year, 11 months ago
C is the correct answer. Stream<T> peek(Consumer<? super T> action); peek is an Intermediate Operation and it returns Stream.
upvoted 3 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