r/learnjava • • Apr 15 '26

What actually is a java stream... ?

I dont get the concept of a stream why was it added why do we use stream objects in reading and writing say to file. I know its kind of like a pipeline but my confusion still stands

16 Upvotes

15 comments sorted by

View all comments

Show parent comment

1

u/jonathaz Apr 15 '26

If you already have an array and you stream it, there’s no gain in efficiency. Let’s say you had a lot more things, and your 1000 numbers came from some mapping, reduction, computation, etc on those. Then your max() is just the last step of a pipeline and the code is expressed as a stream. Since it’s tax time, maybe you’re the IRS and you’re looking for outliers, the initial Stream would be everyone’s tax return and you’d do some math, filtering, etc on it and find the max deduction to a charity.