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):
We don't have time for this. We've gotta save the moon! Or check this out:
Download Free Java APIs to Work with Office Files and PDF