Java.util.stream.Stream - Exam 1Z0-809: Java SE 8 Programmer II | Oracle

Java.util.stream.Stream

Question

Which statement is true about java.util.stream.Stream?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D. E.

B.

The correct answer is E: Stream operation accepts lambda expressions as its parameters.

Here is an explanation of each option:

A. A stream cannot be consumed more than once. This statement is true. Once a terminal operation is performed on a stream, it cannot be reused. Attempting to reuse a stream after a terminal operation has been performed will result in an IllegalStateException.

B. The execution mode of streams can be changed during processing. This statement is also true. The execution mode of a stream can be changed from sequential to parallel and vice versa by invoking the methods sequential() and parallel() on the stream, respectively. However, this should be used with caution as it can impact performance and the results of certain operations.

C. Streams are intended to modify the source data. This statement is false. Streams are intended to perform operations on data from a source and produce a result. They do not modify the source data, but rather create a new stream or collection as output.

D. A parallel stream is always faster than an equivalent sequential stream. This statement is false. Whether a parallel stream is faster than a sequential stream depends on many factors, such as the size of the data set, the complexity of the operations being performed, and the hardware being used. In some cases, a sequential stream may actually be faster than a parallel stream.

E. Stream operation accepts lambda expressions as its parameters. This statement is true. Stream operations accept lambda expressions as parameters. Lambdas provide a concise way of specifying behavior that can be passed as an argument to a method or function. They are used extensively in streams to define operations such as filtering, mapping, and reducing.