How to filter a Map<String,Map<String,Employee>> using Java 8 Filter?
I have to filter only when any of employee in the list having a field value Gender = "M".
Input:
Map<String,Map<String,Employee>>
Output:
Map<String,Map<String,Employee>>
Filter criteria:
Employee.genter = "M"
Also i have to return empty map if the filtered result is empty.
I tried the below, but it is not working as expected. It is returning the only if all the Employees are with gender "M".
tempCollection.entrySet().stream()
.filter(i -> i.getValue().entrySet().stream().allMatch(e-> "M".equals(e.getValue().getGender())))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));