-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStreamCase.java
138 lines (122 loc) · 4.35 KB
/
StreamCase.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package August;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
public class StreamCase {
public static void main(String[] args)
{
Employee[] empList =
{
new Employee("59-385-1088","Zacharias","Schwerin","[email protected]","Male","True",101146,0),
new Employee("73-274-6476","Kyle","Frudd","[email protected]","Male","FALSE",29310,2),
new Employee("85-939-9584","Axe","Gumb","[email protected]","Female","FALSE",62291,4),
new Employee("08-180-8292","Robinet","Batterham","[email protected]","Male","FALSE",142439,4),
new Employee("21-825-2623","Ulick","Burrel","[email protected]","Male","FALSE",128764,5),
new Employee("66-708-5539","Tailor","Ridding","Ridding","Female","FALSE",152924,4),
new Employee("81-697-2363","Joete","Braybrooke","[email protected]","Male","TRUE",128907,0),
new Employee("63-019-1110","Elroy","Baverstock","[email protected]","Male","TRUE",2510,0)
};
System.out.println("********1**********");
List<Employee> clist= Arrays.asList(empList);
List<Employee> abd = (clist.stream().filter(e -> e.getGender().equals("Female")).toList());
System.out.println(abd);
System.out.println(clist.get(0));
System.out.println(clist.stream().filter(e -> e.getGender().equals("Female")));
System.out.println("********2**********");
//method reference//forEach(System.out::println);
//clist.stream().filter(e -> e.getGender().equals("Female")).forEach(e -> System.out.println(e));
clist.stream().filter(e -> e.getGender().equals("Female")).forEach(e ->
{
System.out.println(e);
});
List<Employee> females = Arrays.stream(empList)
.filter(e -> e.getGender().equalsIgnoreCase("Female"))
.collect(Collectors.toList());
System.out.println(females);
System.out.println("********3**********");
clist.stream().filter(e -> e.getNewJoiner().equals("True")).forEach(e -> System.out.println(e));
System.out.println("*********4*********");
// for sort
clist.stream().sorted(Comparator.comparing(Employee::getRating)).forEach(e -> System.out.println(e));
System.out.println("********5**********");
//Match method
boolean sl = clist.stream().allMatch(e -> e.getSalary() > 1000);
System.out.println(sl);
List<Employee> sortedBySalary = Arrays.stream(empList)
.sorted(Comparator.comparingInt(Employee::getSalary))
.collect(Collectors.toList());
System.out.println(sortedBySalary);
}
}
class Employee {
private String empId;
private String firstName;
private String lastName;
private String email;
private String gender;
private String newJoiner;
private int salary;
private int rating;
public Employee(String id, String fn, String ln, String em, String gn, String nj,int i, int j)
{
this.empId = id;
this.firstName= fn;
this.lastName=ln;
this.email=em;
this.gender= gn;
this.newJoiner = nj;
this.salary = i;
this.rating = j;
}
public String getFirstName()
{
return this.firstName;
}
public void setFirstName(String fn){
this.firstName = fn;
}
public String getLastName()
{
return this.lastName;
}
public void setLastName(String ln){
this.lastName = ln;
}
public String getGender()
{
return this.gender;
}
public void setGender(String gn){
this.gender = gn;
}
public String getNewJoiner() {
return this.newJoiner;
}
public void setNewJoiner(String nj){
this.newJoiner = nj;
}
public int getRating() {
return this.rating;
}
public void setRating(int j){
this.rating = j;
}
public int getSalary() {
return this.salary;
}
public void setSalary(int i){
this.salary = i;
}
public void getEmpList()
{
System.out.println(this.empId +this.firstName+this.lastName+this.email+this.gender+this.newJoiner+this.salary+this.rating);
}
public String DisplayString()
{
return "Employee: " + firstName+ " " + lastName+
", Gender: " + gender +", New Joiner: " + newJoiner +
", Salary: " + salary +
", Rating: " + rating;
}
}