forked from LuigiCortese/java-certification-ocp8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.java
67 lines (48 loc) · 1.98 KB
/
App.java
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package net.devsedge.stream.creation;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;
public class App {
public static void main(String[] args) {
/*
* Stream creation...
*/
// ...empty
Stream<Object> s = Stream.empty();
IntStream s1 = IntStream.empty();
LongStream s2 = LongStream.empty();
DoubleStream s3 = DoubleStream.empty();
// ...from values
Stream<String> s4 = Stream.of("a","b","c");
Stream<Integer> s5 = Stream.of(1,2,3);
Stream<Object> s6 = Stream.of(new Object(),new Object());
// ...with a stream builder
Stream<String> s7 = Stream.<String>builder().add("a").add("b").add("c").build();
Stream<Integer> s8 = Stream.<Integer>builder().add(1).add(2).add(3).build();
Stream<Object> s9 = Stream.<Object>builder().add(new Object()).add(new Object()).build();
// ...from function (ordered)
Stream<String> s10 = Stream.iterate("|0|", x -> x+"_|");
Stream<Integer> s11 = Stream.iterate(1, n -> n + 2);
Stream<Integer> s12 = Stream.iterate(1, n -> n + 2).limit(10);
// ...from function (unordered)
Stream<Double> s13 = Stream.generate(Math::random).limit(5);
// ......from arrays
Stream<String> s14 = Arrays.stream(new String[] {"A", "B"});
Stream<Integer> s15 = Arrays.stream(new Integer[]{1, 2, 3});
IntStream s16 = Arrays.stream(new int[]{1, 2, 3});
// ...from collections
Stream<String> s17 = new ArrayList<String>().stream();
Stream<String> s18 = new ArrayList<String>().parallelStream();
// ...from File
try {
Stream<String> lines = Files.lines(Paths.get("path/file.txt"));
} catch (IOException e) {
}
}
}