public class EmployeeService { public static List getEmployees() { ArrayList employeesArrList = new ArrayList(); employeesArrList.add(new Employee(7921, "Turner", 5000.0, "Male")); employeesArrList.add(new Employee(7802, "Blake", 4000.0, "Male")); employeesArrList.add(new Employee(7167, "Mark", 8000.0, "Male")); employeesArrList.add(new Employee(7177, "Alice", 5000.0, "Female")); employeesArrList.add(new Employee(7788, "Scott", 6000.0, "Male")); employeesArrList.add(new Employee(7044, "Sophia", 7000.0, "Female")); employeesArrList.add(new Employee(7289, "Allen", 3000.0, "Male")); employeesArrList.add(new Employee(7511, "Mary", 4000.0, "Female")); return employeesArrList; } // fetch "Female" employees public List fetchFemaleEmployees() { List employees = EmployeeService.getEmployees(); /* Stream stream1 = employees.stream(); Stream stream2 = stream1.filter( e -> e.getGender().equalsIgnoreCase("Female")); List femaleEmployees = stream2.toList(); return femaleEmployees; */ return employees .stream() .filter( e -> e.getGender().equalsIgnoreCase("Female") ) .toList(); } // add 10% hike for "Male" employees. public List employeesAfterHike() { List employees = EmployeeService.getEmployees(); /* Stream stream1 = employees.stream(); Stream stream2 = stream1.filter(e -> e.getGender().equalsIgnoreCase("Male")); Stream stream3 = stream2.map( e -> { e.setSalary(e.getSalary() * 1.1); return e; }); List maleEmployees = stream3.collect(Collectors.toList()); return maleEmployees; */ return employees .stream() .filter(e -> e.getGender().equalsIgnoreCase("Male")) .map(e -> { e.setSalary(e.getSalary() * 1.1); return e; }) .collect(Collectors.toList()); } // fetch top paid employee public Employee topPaidEmployee() { List employees = EmployeeService.getEmployees(); return employees .stream() .max((e1, e2) -> { if (e1.getSalary() < e2.getSalary()) return -1; else if(e1.getSalary() == e2.getSalary()) return 0; else return 1; }) .get(); } // fetch top3 paid employees public List top3PaidEmployees() { List employees = EmployeeService.getEmployees(); return employees .stream() .sorted((e1, e2) -> { if(e1.getSalary() < e2.getSalary()) return 1; else if(e1.getSalary() == e2.getSalary()) return 0; else return -1; }) .limit(3) .toList(); } }