-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjava8example.java
63 lines (48 loc) · 1.45 KB
/
java8example.java
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package java8ex;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class Listadd {
public static void main(String[] args) {
List<Student_details> list=Arrays.asList(
new Student_details("ravi",12,"M"),
new Student_details("ram",54,"M"),
new Student_details("sania",25,"F"),
new Student_details("kuresh",60,"M"),
new Student_details("sonia",28,"F")
);
// Student_details result=list.stream()
// .filter(x->"ravi".equals(x.getName()))
// .findAny()
// .orElse(null);
// System.out.println(result);
Student_details result=list.stream()
.filter((p->p.age<50))
.findAny()
.orElse(null);
System.out.println(result);
System.out.println(result.getAge());
// list.stream()
// .filter(p->p.age<50)
// .map(pm->pm.age)
// .forEach(System.out::println);
List<Integer> collect= list.stream()
.filter(p->p.age<50)
.map(Student_details::getAge)
.collect(Collectors.toList());
//collect.forEach(System.out::println);
System.out.println(collect);
List<Object> listage =list.stream()
.filter(p1->p1.age<50)
//.forEach(System.out::println);
.collect(Collectors.toList());
// .findAny()
// .orElse(null);
System.out.println(listage);
List<Integer> collectage= list.stream()
.map(Student_details::getAge)
.collect(Collectors.toList());
//collectage.forEach(System.out::println);
System.out.println(collectage);
}
}