Filter a list with condition on inner list

Viewed 1209

I have a list of objects. Each object contains another list. I want to filter the list with condition on inner list.

For example:

There is a list of factories. Each factory contains a list of different car models it produces. I want to filter factory list in such way that I will get only factories that produce Mazda3.

How can I do it with lambda?

It should be something similar to this:

factories.stream().filter(f -> f.getCars().stream().filter(c -> C.getName().equals("Mazda3")).).collect(Collectors.toList());
2 Answers
Related