with - stream api in java 8 javatpoint
Java IntStream iterate vs generate when to use what? (2)
IntStream.iteratereturns an ordered
IntStreamon the other hand
IntStream.generatereturns an unordered
IntStreamwhich can help in speeding up parallel stream pipelines.
IntStream.generateare preferred to generate random or constant values as specified in the Javadoc, I would guess most likely for the characteristics of the stream returned.
is just a lightweight ordered version for
Is it true? If not, what is the core difference?
Aside from order, also the usage is a bit different. Let's look at the method signatures:
iterate(int seed, IntUnaryOperator f)
Iterate has explicitly given starting value as parameter and unary operator which is used to generate next value from previous. Here operator can easily be immutable without internal state and can be reused in multiple places in parallel without any issue.
Generate uses supplier. Those can either provide constant or random numbers or need to have internal state to provide series like (1, 2, 3, ...).