-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyLambdaExample.java
More file actions
executable file
·36 lines (26 loc) · 910 Bytes
/
Copy pathMyLambdaExample.java
File metadata and controls
executable file
·36 lines (26 loc) · 910 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
36
package lambda;
import java.util.Arrays;
import java.util.List;
/**
* Created by gaurav on 15/9/17.
*/
public class MyLambdaExample {
public static void main(String args[]) {
//Print a list of integers with a lambda
List<Integer> intSeq = Arrays.asList(1, 2, 3);
intSeq.forEach(x -> System.out.println("Print a list of integers with a lambda::" + x));
//A multiline lambda
// List<Integer> intSeq = Arrays.asList(1, 2, 3);
intSeq.forEach(x -> {
x += 2;
System.out.println("A multiline lambda:::" + x);
});
// A lambda with a defined local variable
intSeq.forEach(x -> {
int y = x * 2;
System.out.println("A lambda with a defined local variable::"+y);
});
int var = 10;
intSeq.forEach(x -> System.out.println("--Variable capture--"+(x + var)));
}
}