-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathExample1.java
More file actions
35 lines (29 loc) · 926 Bytes
/
Example1.java
File metadata and controls
35 lines (29 loc) · 926 Bytes
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
package Java8;
import java.util.Arrays;
import java.util.List;
public class Example1 {
public static void main(String[] args) {
List<Integer> values = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
//printUsingJava7(values);
printUsingJava8(values);
}
private static void printUsingJava8(List<Integer> values) {
System.out.println("Java 8 using lambda expression");
System.out.println("type 1");
values.forEach(value -> {
System.out.println(value);
});
System.out.println("type 2");
values.forEach(System.out::println);
}
private static void printUsingJava7(List<Integer> values) {
System.out.println("Java 7 Type 1 using simple for loop");
for (int i = 0; i < values.size(); i++) {
System.out.println(values.get(i));
}
System.out.println("Java 7 Type 2 using for each loop");
for (Integer value : values) {
System.out.println(value);
}
}
}