I have a list named "foodList" which contains elements of type "Food". The object Food contains a List named "categories" of type "Category".
I am currently implementing a search algorithm to filter food by excluding certain categories.
Excluded Categories are stored inside a List named "excludedCategories".
How can I, using Java 8 and streams, filter the foodList by excluding Food objects whose categoryLists contain any element of the excludedCategories list?
Sample code with loops:
for (Food f: foodList)
{
for (Category c: f.categories)
{
if (excludedCategories.contains(c))
{
// REMOVE ITEM FROM foodList
}
}
}
Thank you!
enumand using anEnumSetinstead of aList<Category>.