forked from winterbe/java8-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreams13.java
More file actions
26 lines (21 loc) · 709 Bytes
/
Streams13.java
File metadata and controls
26 lines (21 loc) · 709 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.winterbe.java8.samples.stream;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.stream.IntStream;
/**
* @author Benjamin Winterberg
*/
public class Streams13 {
public static void main(String[] args) {
SecureRandom secureRandom = new SecureRandom(new byte[]{1, 3, 3, 7});
int[] randoms = IntStream.generate(secureRandom::nextInt)
.filter(n -> n > 0)
.limit(10)
.toArray();
System.out.println(Arrays.toString(randoms));
int[] nums = IntStream.iterate(1, n -> n * 2)
.limit(11)
.toArray();
System.out.println(Arrays.toString(nums));
}
}