Issue
Lets say we have employee table and we are caching the entire data on startup to avoid db roundtrips due to large dataset. Employee Object looks like below
public class Employee {
private String employeeID;
private String department;
private LocalDate joiningDate;
//getters and setters
}
List<Employee> employeeList = employeeInfoCache.getEmployeeList();
I would like to get the list of employees joined between two dates from this list?
Solution
I am not sure if I understood the question and in case I apologise
Pseudo code
List<Employee> filteredList = employeeList.stream()
.filter(e -> date1 < e.joiningDate && e.joiningDate < date2)
.collect(Collectors.toList());
assuming date is in UNIX epoch time.
Consider using a parallelStream.
Answered By - Gurgolo
Answer Checked By - Gilberto Lyons (JavaFixing Admin)