Why doesn’t my Java Stream do anything?

https://medium.com/@aev_software/why-doesnt-my-java-stream-do-anything-a3651b4234dd

Chances are you forgot to kick it.

The linked article is written by me. It explains how Java streams need a terminating operation in order to start any actions. For more explanations and code examples, do follow the link and read the article. It's free.

1 points · 2 comments · view on lemmy.world

2 Comments

JackbyDev@programming.dev · 4 pts · 3y (1 reply)

The only time I've had to have a "pointless" terminal operation was in some contrived unit test code. I remember putting a comment on the line saying something like "terminal operation so the stream does something" lol. But yeah, I can see this being extremely confusing to novices trying to learn the Stream API on their own.

aev@lemmy.sdf.org · 2 pts · 3y

Right! I had used streams a couple of times but for most work had switched to Eclipse Collections. Some payloads just work better when streamed and I was left wondering why nothing happened!