Skip to content

Commit 7fea695

Browse files
authored
Create ForEachConsSpec.java
1 parent 063d6bd commit 7fea695

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.zetcode;
2+
3+
import java.util.Arrays;
4+
import java.util.function.DoubleConsumer;
5+
import java.util.function.IntConsumer;
6+
import java.util.function.LongConsumer;
7+
8+
public class ForEachConsSpec {
9+
10+
public static void main(String[] args) {
11+
12+
int[] inums = { 3, 5, 6, 7, 5 };
13+
IntConsumer icons = i -> System.out.print(i + " ");
14+
Arrays.stream(inums).forEach(icons);
15+
16+
System.out.println();
17+
18+
long[] lnums = { 13L, 3L, 6L, 1L, 8L };
19+
LongConsumer lcons = l -> System.out.print(l + " ");
20+
Arrays.stream(lnums).forEach(lcons);
21+
22+
System.out.println();
23+
24+
double[] dnums = { 3.4d, 9d, 6.8d, 10.3d, 2.3d };
25+
DoubleConsumer dcons = d -> System.out.print(d + " ");
26+
Arrays.stream(dnums).forEach(dcons);
27+
28+
System.out.println();
29+
}
30+
}

0 commit comments

Comments
 (0)