There's nothing wrong with skip()
, you've asked to skip 1
element, and it always does so. The stream created by Stream.of()
is ordered and skip()
gives a guarantee that encounter order would always be taken into account.
is constrained to skip not just any n
elements, but the first n
elements in the encounter order.
Because we don't see 10
in the output, that's the proof that skip()
does its job correctly - element 1
never reaches the terminal operation.
There's no output from peek()
in parallel (1
is not printed).
This method operates via side effects and according to the API note "exists mainly to support debugging". Contrary to forEach()
/forEachOrdered()
it's an intermediate operation which is not meant to perform the resulting action. API documentation warns that it could be elided, and you shouldn't rely on it.
The eliding of side-effects may also be surprising. With the exception of terminal operations forEach
and forEachOrdered
, side-effects of behavioral parameters may not always be executed when the stream implementation can optimize away the execution of behavioral parameters without affecting the result of the computation.