-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamExamples.java
More file actions
44 lines (32 loc) · 1.29 KB
/
Copy pathStreamExamples.java
File metadata and controls
44 lines (32 loc) · 1.29 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
package Session_18_JavaStreams;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class StreamExamples {
public static void main(String... args) {
List<String> strignList = Arrays.asList("a", "b", "c");
Stream<String> stringListStream = strignList.stream();
Map<String, Integer> map = new HashMap<>();
map.put("Ana", 25);
map.put("Ion", 30);
Stream<String> keyStream = map.keySet().stream();
Stream<Integer> valStream = map.values().stream();
//-----------------------------------------------------------------------
int[] nr = {1, 2, 3, 4, 5};
IntStream nrStream = Arrays.stream(nr);
//-------------------------------------------------------------------------
Stream<String> customStream = Stream.of("a", "b", "c");
//-------------------------------------------------------------------------
try (Stream<String> lines = Files.lines(Path.of("example.txt"))) {
lines.forEach(System.out::println);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}