Java 8 apply function to all elements of Stream without breaking stream chain
There are (at least) 3 ways. For the sake of example code, I’ve assumed you want to call 2 consumer methods methodA and methodB: A. Use peek(): list.stream().peek(x -> methodA(x)).forEach(x -> methodB(x)); Although the docs say only use it for “debug”, it works (and it’s in production right now) B. Use map() to call methodA, … Read more