Page 1 of 1

About Question enthuware.ocpjp.v8.2.1856 :

Posted: Mon Mar 21, 2016 8:38 am
by surzhin
As per https://docs.oracle.com/javase/tutorial ... s/streams/:

A pipeline contains the following components:
A source: This could be a collection, an array, a generator function, or an I/O channel. In this example, the source is the collection roster.
Zero or more intermediate operations: An intermediate operation, such as filter, produces a new stream.
A terminal operation.

1. a source
2. an intermediate operation
3. a terminal operation
4. a reduction operation
5. a method reference
6. a lambda expression

You had to select 2 options. Why only two options?
So , 1 and 3. But why the operation number 2 is wrong?

Re: About Question enthuware.ocpjp.v8.2.1856 :

Posted: Mon Mar 21, 2016 10:22 am
by admin
The statement that you've quoted says, "zero or more intermediate operations". That means an intermediate operation is not a must for a pipeline. That is why option 2 is incorrect.

HTH,
Paul.

Re: About Question enthuware.ocpjp.v8.2.1856 :

Posted: Thu Aug 25, 2016 7:46 am
by ramy6_1
Hello,

If an intermediate operation is optional , how we can use a pipeline ?

Can you provide a sample case using stream and terminal operation only ?

Re: About Question enthuware.ocpjp.v8.2.1856 :

Posted: Tue Aug 30, 2016 3:10 am
by ramy6_1
Hello ,

Appreciate your update.

Re: About Question enthuware.ocpjp.v8.2.1856 :

Posted: Tue Aug 30, 2016 12:21 pm
by admin
Not sure I understand your question. Taking the example from the link mentioned above:
roster.stream().forEach(e -> System.out.println(e.getName()));
is a valid pipeline without any intermediate operation.



-Paul.

Re: About Question enthuware.ocpjp.v8.2.1856 :

Posted: Fri Oct 16, 2020 10:30 am
by vleunti
But this is also valid

roster.stream().filter(x->x.isEmpty());

source and intermediate operation, here we have no terminal operation. So, terminal operation is not a must, isn't ?

Re: About Question enthuware.ocpjp.v8.2.1856 :

Posted: Fri Oct 16, 2020 10:42 am
by admin
It is valid as in valid code but will not do anything. Unless you have a terminal operation, nothing will be executed. So, it is not valid from the pipeline perspective.

Re: About Question enthuware.ocpjp.v8.2.1856 :

Posted: Wed Oct 28, 2020 7:45 am
by Deleted User 6318
What would be the generator function source?