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.

Full stack developer