List<Long> list = Arrays.stream(value).map(result ->{
final Long id = result[1];
if(id == null){
continue; // This part doesn't work (error: Continue outside of loop)
}
return id;
}).collect(Collectors.toList());
关于.streams为什么会发生这种情况的任何建议?而当我不使用流时,可以使用。 该问题已被标记为重复,但事实并非如此。使用continue
return
当然可以在forEach
中使用,不需要返回类型,但在map
中则不需要。我有这个简单的代码,在其中使用流和.map()函数。我对id进行了空检查,并在其中添加了continue,continue给了我一个错误:循环外继续,当我删除...
continue
在for循环中工作。您可以使用flatMap
作为解决方法: