有一些Java代码:
List<Call> updatedList = updatingUniquedList
.stream()
.map(s -> {
Call call = callsBufferMap.get(s);
}
return call;
}).collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
如果调用变量为空,如何避免添加到最终列表?
考虑我有一个Optional对象的数组列表,例如List<Visit> visit = {Optional[Visit], Optional[Visit], ...}. 我如何Visit从 获取对象Optional并将这些对象作为 a 返回List?
我尝试过这样的事情:
return Stream.of(visits).filter(value -> Optional.isPresent(value))
.map((Visit t) -> Optional.get(t))
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
和这个:
return Stream.of(visits)
.map(visit -> Optional.of(visit).get())
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
但这不能编译。
我正在尝试使用Lightweight-Stream-API作为流库。