-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathStreamingAPI.java
More file actions
104 lines (85 loc) · 2.28 KB
/
Copy pathStreamingAPI.java
File metadata and controls
104 lines (85 loc) · 2.28 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package collection;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
class Student{
Student(int id, String name){
this.id = id;
this.name = name;
}
int id;
String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class StreamingAPI {
public static void main(String[] args) {
List<Student> sList = new ArrayList<Student>();
sList.add(new Student(1, "Abhisek"));
sList.add(new Student(2, "Milan"));
sList.add(new Student(3, "Bibhu"));
sList.add(new Student(4, "Ashok"));
sList.add(new Student(5, "Subrat"));
sList.add(new Student(6, "Jay"));
sList.add(new Student(7, "Prem"));
sList.add(new Student(8, "Situ"));
sList.add(new Student(9, "Vikas"));
sList.add(new Student(10, "Ranjit"));
sList.forEach(student -> {
System.out.println(student.getName());
});
List<String> nameList = sList
.stream()
.map(Student::getName)
.filter(name->{
return name.startsWith("A");
})
.limit(10)
.collect(Collectors.toList());
System.out.println("-------------*************-----------------");
List<String> filterStr = sList.stream().map(Student::getName).filter(name->{
if(name.endsWith("t")){
return true;
}else{
return false;
}
}).limit(10).collect(Collectors.toList());
filterStr.forEach(name -> {
System.out.println(name);
});
System.out.println("-------------*************-----------------");
nameList.forEach(e->{
System.out.println("----"+e);
});
for(String s:nameList){
System.out.println("----"+s);
}
List<Student> newList = sList
.stream()
.filter(ele->{
return ele.name.startsWith("A");
})
.limit(10)
.collect(Collectors.toList());
int totalSum = sList.stream().map(Student::getId).filter(e->{
if(e<4)
return true;
else
return false;
}).mapToInt(e->e).sum();
System.out.println("-----------"+totalSum);
newList.forEach(student -> {
System.out.println(student.getName());
});
}
}