-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLambdaExpression.java
More file actions
42 lines (35 loc) · 1.04 KB
/
LambdaExpression.java
File metadata and controls
42 lines (35 loc) · 1.04 KB
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
37
38
39
40
41
42
package LambdaExpression;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class LambdaExpression {
public static void main(String[] args) {
List<Integer> arrayList = new ArrayList<>();
arrayList.add(10);
arrayList.add(11);
arrayList.add(12);
arrayList.add(13);
arrayList.add(14);
arrayList.add(15);
List<Integer> integerLessThan13 = filter(arrayList, (Integer integer) -> {
return integer >= 12;
});
List<Integer> integergeterthen12 = filter(arrayList, new Filterable() {
@Override
public boolean apply(Integer persion) {
return persion >= 12;
}
});
System.out.print(Arrays.asList(integerLessThan13));
System.out.print(Arrays.asList(integergeterthen12));
}
public static List<Integer> filter(List<Integer> arrayList, Filterable filterable) {
List<Integer> filterInteger = new ArrayList<>();
for (Integer persion : arrayList) {
if (filterable.apply(persion)) {
filterInteger.add(persion);
}
}
return filterInteger;
}
}