【发布时间】:2022-06-10 21:31:31
【问题描述】:
我有对象 FastFood。在 ArrayList 中有 10 条热狗。
public class FastFood {
ArrayList<Hotdog> hotdogs;
boolean isTasty;
}
public class Hotdog {
String name;
Ingredients ingredients;
}
对于 9 条热狗,所有数据都已填满。 对于 1 个热狗,对象成分为空。
我怎样才能修改下面的方法以只包含这些热狗,这些热狗已经填充了成分? (我想看 9 条热狗)。
public List<Hotdog> convert(Fastfood fastfood) {
List<Hotdog> hotdogs = fastfood.getHotdogs().stream()
.map(this::convertToHotdog)
.collect(Collectors.toList());
【问题讨论】: