It totally depends upon the exact scenario. Sometimes the sequence of operations makes a lot of difference like flatMap() and groupingBy() are completely opposite functions. In your example you are using groupingBy() then map() and then flatMap() and then filter(). If possible the sequence can be filter() then map() and then collect() that's it. We can remove the groupingBy() and flatMap(). But sometimes we have to create some long stream sequence as you mentioned.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store