How to filter a map by its values in Java 8?

If I understand your filtering criteria correctly, you want to check if the filtered Stream you produced from the value List has any elements, and if so, pass the corresponding Map entry to the output Map.

Map<String, List<BoMLine>>
    filtered = materials.entrySet()

This is assuming MaterialDao.findMaterialByName(l.getMaterial()) returns a boolean.

Leave a Comment