About Question enthuware.ocpjp.v8.2.1856 :
Moderator: admin
-
- Posts: 7
- Joined: Fri Dec 11, 2015 6:50 am
- Contact:
About Question enthuware.ocpjp.v8.2.1856 :
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?
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?
-
- Site Admin
- Posts: 10068
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1856 :
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.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 124
- Joined: Wed Feb 12, 2014 2:44 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1856 :
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 ?
If an intermediate operation is optional , how we can use a pipeline ?
Can you provide a sample case using stream and terminal operation only ?
-
- Posts: 124
- Joined: Wed Feb 12, 2014 2:44 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1856 :
Hello ,
Appreciate your update.
Appreciate your update.
-
- Site Admin
- Posts: 10068
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1856 :
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.
roster.stream().forEach(e -> System.out.println(e.getName()));
is a valid pipeline without any intermediate operation.
-Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 4
- Joined: Tue Aug 25, 2020 3:50 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1856 :
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 ?
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 ?
-
- Site Admin
- Posts: 10068
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1856 :
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.
If you like our products and services, please help us by posting your review here.
-
- Posts: 61
- Joined: Sat Feb 15, 2020 8:56 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1856 :
What would be the generator function source?
Who is online
Users browsing this forum: No registered users and 131 guests