Piet Souris wrote:hi Ruben,
welcome to the Ranch and enjoy the stay!
A stream can be without a terminal operation. In that case the stream is not executed.
Mikalai Zaikin wrote:I would say there is a big difference between stream and stream pipeline ;)
Stream is an approach to access data stored in some backed storage (collection, file, generator)
Pipeline -- consists of a stream, zero or more intermediate operation, and exactly one terminal operation.
Mikalai Zaikin wrote:I think it's more English language area
"at most one" means "not more than one" (IMHO)
and "one" falls into this category
Jeanne Boyarsky wrote:There is precision and there is reading into things .
We use stream and stream pipeline interchangeably in many places in the book. We are careful where it matters. For example the stream() method is not a pipeline.
Yes, "at most one" means "not more than one". Which means "optional". The terminal option isn't required. However, the pipeline isn't useful with one because it returns a stream reference instead of executing.
Jeanne Boyarsky wrote:No. A is still true. I think you might find it easier to understand why the opposite is false.
Inverting option A gives "A stream can have more than one terminal operations". That's clearly false. We both agree there can't be two.
Stephan van Hulst wrote:No, that is incorrect.
A stream pipeline can have zero terminal operations without problems. It just doesn't do anything.
Which are true statements about terminal operations in a stream that runs successfully?
Stephan van Hulst wrote:
I will admit I may have caused some confusion with my previous post. In that post, I said that a stream pipeline may have zero terminal operations. I made that assertion about some stream, not the specific case of "a stream that runs successfully", which was mentioned in the original problem statement. Here's a simple proof:
This piece of code creates a stream pipeline with one intermediate operation and zero terminal operations. It does not do anything useful, but the program compiles and runs just fine.