-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilterEmployeeBySalary.java
More file actions
35 lines (26 loc) · 1002 Bytes
/
Copy pathFilterEmployeeBySalary.java
File metadata and controls
35 lines (26 loc) · 1002 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.List;
public class FilterEmployeeBySalary {
public record Employee(
int id,
String name,
double salary,
String department) {
}
public static List<Employee> filterBySalary(List<Employee> employees, double minSalary) {
return employees.stream()
.filter(employee -> employee.salary() >= minSalary)
.toList(); // Java 16+
}
public static void main(String[] args) {
List<Employee> employees = List.of(
new Employee(1, "John", 65000, "IT"),
new Employee(2, "Mary", 95000, "Finance"),
new Employee(3, "David", 85000, "HR"),
new Employee(4, "Sarah", 120000, "Engineering"),
new Employee(5, "Mike", 70000, "IT")
);
double minimumSalary = 80000;
List<Employee> result = filterBySalary(employees, minimumSalary);
result.forEach(System.out::println);
}
}