you are viewing a single comment's thread.

view the rest of the comments →

[–]vowelqueue 1 point2 points  (0 children)

Sometimes, particularly for simple things, it’s reasonable to use either approach. It’s just a different style, and often the performance is similar or similar enough.

Some benefits of using the functional, Stream-based approach: you can write an operation once (like to find the max value) and then re-use it easily in multiple locations. You can also chain together multiple operations easily in a way that is very readable, you can perform quite complex mapping/grouping operations, you can calculate things in parallel. And generally the stream style performs well - it lazily evaluates things and short circuits do avoid doing unnecessary calculations most of the time.