Im learning about Stream and have the following question. Why is the first peek() method not destructive, and thus flatMap() and forEach() are executed. And in the second stream the count() method is not reached because the peek() is destructive?
Bart Boersma wrote:stream2.peek(System.out::print).count(); // Why is count() ignored? Why is peek() destructive for the stream? Why is count() never reached?
That is an example why to use an IDE is not a good idea when preparing for a certification exam. It gives misdirection and you just overlook foundations, and that is becacuse IDE suggestion (am I right?).
How you decided count() is never reached? What actually is, that count is being calculated, but not stored in a variable, so result simply gets discarded.
Have that line as (and you'll see yourself):
when in doubt - just merge, and never rebase
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database