I think it would be better, especially if you are doing multi-threaded work, so that the stream from the original list to a new modified list or something else is needed.
A new list or map, or any other structure you desire, can be created as part of the streaming process.
When the streaming process is complete, simply replace the original with a new one.
All this should happen in a synchronized block.
This way you get maximum performance and parallelism to reduce or what you do, and end up with an atomic swap.
Rodney P. Barbati
source share