forked from BruceEckel/OnJava8-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamFromArray.java
More file actions
51 lines (46 loc) · 1.18 KB
/
StreamFromArray.java
File metadata and controls
51 lines (46 loc) · 1.18 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// arrays/StreamFromArray.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;
import onjava.*;
public class StreamFromArray {
public static void main(String[] args) {
String[] s = new Rand.String().array(10);
Arrays.stream(s)
.skip(3)
.limit(5)
.map(ss -> ss + "!")
.forEach(System.out::println);
int[] ia = new Rand.Pint().array(10);
Arrays.stream(ia)
.skip(3)
.limit(5)
.map(i -> i * 10)
.forEach(System.out::println);
Arrays.stream(new long[10]);
Arrays.stream(new double[10]);
// Only int, long and double work:
//- Arrays.stream(new boolean[10]);
//- Arrays.stream(new byte[10]);
//- Arrays.stream(new char[10]);
//- Arrays.stream(new short[10]);
//- Arrays.stream(new float[10]);
// For the other types you must use wrapped arrays:
float[] fa = new Rand.Pfloat().array(10);
Arrays.stream(ConvertTo.boxed(fa));
Arrays.stream(new Rand.Float().array(10));
}
}
/* Output:
eloztdv!
ewcippc!
ygpoalk!
ljlbynx!
taprwxz!
47200
61770
84790
66560
37680
*/