LongStream generate(LongSupplier s) example
Description
LongStream generate(LongSupplier s)
returns an infinite sequential unordered stream where each element is generated by the provided LongSupplier.
Syntax
generate
has the following syntax.
static LongStream generate(LongSupplier s)
Example
The following example shows how to use generate
.
import java.util.stream.LongStream;
/*ww w . j a va2 s. com*/
public class Main {
public static void main(String[] args) {
LongStream b = LongStream.generate(()->{return 2L;});
b.limit(10).forEach(System.out::println);
}
}
The code above generates the following result.