The 30 second answer
map transforms each element into a new value. peek runs an action and passes the same element through, and the Javadoc says it exists mainly for debugging. Since Java 9 the pipeline may skip peek when the result can be computed directly, so I never put real business side effects there.
map transforms; peek performs an action and passes the same element through. Javadoc: peek "exists mainly to support debugging".
Since Java 9, an implementation may skip executing the pipeline (and so peek) when it can compute the result directly — for example count() on a SIZED source. Never put business side effects in peek.
Sources:
Sources (0)
See inline citations in the answer above.