I have the object FastFood. In ArrayList there are 10 hotdogs.
public class FastFood {
ArrayList<Hotdog> hotdogs;
boolean isTasty;
}
public class Hotdog {
String name;
Ingredients ingredients;
}
For 9 hotdogs all data is filled. For 1 hotdog, the object Ingredients is null.
How can I modify below metod to have only these hotdogs, which have filled Ingredients? (I would like to see 9 hotdogs).
public List<Hotdog> convert(Fastfood fastfood) {
List<Hotdog> hotdogs = fastfood.getHotdogs().stream()
.map(this::convertToHotdog)
.collect(Collectors.toList());
nullproperty you need to applyfilter(), or if you don't need them at all you can usefastfood.getHotdogs().removeIf(hd -> hd.getIngredients() == null);instead of creating a stream. What does the methodconvertToHotdogis meant to do?getHotdogs()returns a list ofHotdogs and result is alsoList<Hotdog>, so what is happening in between?