How can i filter employee list based on the "City filter list" and maintain the filter order using java 8.
I want to filter Employee (list1) objects by city name based on the another list(filterList : referring City) and create new list(list2) and maintain hte filterList City order using Java 8.
Important Note : Here new list should be in same order where the filterList(City name) there.
Input :
List<Employee> list1 = Stream.of(
new Employee("100","Boston","Massachusetts"),
new Employee("400","Atlanta","Georgia"),
new Employee("300","pleasanton","California"),
new Employee("200","Decatur","Texas"),
new Employee("500","Cumming","Atlanta"),
new Employee("98","sula","Maine"),
new Employee("156","Duluth","Ohio"))
.collect(Collectors.toList());
Filter List :
List<String> filterList = Stream.of("pleasanton", "Atlanta", "Cumming", "Boston").collect(Collectors.toList());
Expected output :
List<Employee> list2 = Stream.of(
new Employee("300","pleasanton","California"),
new Employee("400","Atlanta","Georgia"),
new Employee("500","Cumming","Atlanta"),
new Employee("100","Boston","Massachusetts"))
.collect(Collectors.toList());