We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 895575c commit 98ac2d0Copy full SHA for 98ac2d0
src/com/winterbe/java8/Streams4.java
@@ -0,0 +1,37 @@
1
+package com.winterbe.java8;
2
+
3
+import java.util.OptionalInt;
4
+import java.util.stream.IntStream;
5
6
+/**
7
+ * @author Benjamin Winterberg
8
+ */
9
+public class Streams4 {
10
11
+ public static void main(String[] args) {
12
+ for (int i = 0; i < 10; i++) {
13
+ if (i % 2 == 1) {
14
+ System.out.println(i);
15
+ }
16
17
18
+ IntStream.range(0, 10)
19
+ .forEach(i -> {
20
+ if (i % 2 == 1) System.out.println(i);
21
+ });
22
23
24
+ .filter(i -> i % 2 == 1)
25
+ .forEach(System.out::println);
26
27
+ OptionalInt reduced1 =
28
29
+ .reduce((a, b) -> a + b);
30
+ System.out.println(reduced1.getAsInt());
31
32
+ int reduced2 =
33
34
+ .reduce(7, (a, b) -> a + b);
35
+ System.out.println(reduced2);
36
37
+}
0 commit comments