I have a list myListToParse
where I want to filter the elements and apply a method on each element, and add the result in another list myFinalList
.
I prefer the second way.
When you use the first way, if you decide to use a parallel stream to improve performance, you'll have no control over the order in which the elements will be added to the output list by forEach
.
When you use toList
, the Streams API will preserve the order even if you use a parallel stream.