在 Java 8 中映射后过滤空值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40777874/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Filter null values after map in Java 8
提问by cybertextron
I'm new in using map
and filters
in Java 8. I'm currently using Spark ML
library for some ML algorithms.
I have the following code:
我在使用新的map
和filters
在Java中8.我目前使用的Spark ML
库对于一些ML算法。我有以下代码:
// return a list of `Points`.
List<Points> points = getPoints();
List<LabeledPoint> labeledPoints = points.stream()
.map(point -> getLabeledPoint(point))
.collect(Collectors.toList());
The function getLabeledPoint(Point point)
returns a new LabeledPoint
if the data is correct or null otherwise. How can I filter (remove) the null
LabeledPoint
objects after map
?
如果数据正确,该函数getLabeledPoint(Point point)
返回一个新的,LabeledPoint
否则返回空。之后如何过滤(删除)null
LabeledPoint
对象map
?