I have a list of products. Each product holds another list of ingredients. How can I use Streams in order to get a list of all ingredients from all products?
products.stream()
.map(Product::getIngredients())
.filter(i -> !i.isEmpty())
.distinct()
.collect(Collectors.toList());
Above the code as far as I got, so far I'm just getting a list with sublists...
What's the right way to do this?
Thanks a lot!
Stream.flatMap: docs.oracle.com/javase/8/docs/api/java/util/stream/…