-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLambdaTest.java
More file actions
35 lines (27 loc) · 786 Bytes
/
LambdaTest.java
File metadata and controls
35 lines (27 loc) · 786 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
import java.util.ArrayList;
/**
* @author Divyam (https://github.com/DevYam)
* @created 04/09/2020 - 10:19
* @project java
*/
public class LambdaTest {
// A java program to implement simple lambada expression
public static void main(String[] args) {
ArrayList<Integer> arr = new ArrayList<>();
arr.add(1);
arr.add(2);
arr.add(3);
arr.add(14);
// Using lambada expression
arr.forEach(n -> System.out.println(n));
// Using consumer
arr.forEach(System.out::println);
//Using lambda to print even
System.out.println("Now printing only even numbers \n");
arr.forEach(n ->{
if (n%2 == 0){
System.out.println(n);
}
});
}
}