Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在添加到集合之前过滤对象的最干净方法?_Java_Lambda_Coding Style_Java Stream - Fatal编程技术网

Java 在添加到集合之前过滤对象的最干净方法?

Java 在添加到集合之前过滤对象的最干净方法?,java,lambda,coding-style,java-stream,Java,Lambda,Coding Style,Java Stream,确切的流量当量为: filesnames.forEach(fileName -> parseObject(fileName)).(some method that takes the output of parseObject) 您可以使用filenames.stream().map(this::parseObject).filter(object->Objects.equals(property1,object.getProperty1()).collect(Collectors.to

确切的流量当量为:

filesnames.forEach(fileName -> parseObject(fileName)).(some method that takes the output of parseObject)

您可以使用
filenames.stream().map(this::parseObject).filter(object->Objects.equals(property1,object.getProperty1()).collect(Collectors.toList())
。什么是
?那好多了,谢谢。为什么不干脆
收集器。toList
?@Naman有一次有人告诉我,“可以肯定,万一toList的实现发生变化”,如果Ousmane这样想的话,idk
filesnames.forEach(fileName -> parseObject(fileName)).(some method that takes the output of parseObject)
return filenames.stream()
         .map(filename -> parseObject(filename))
         .filter(o -> o.getProperty1() == property1)
         .collect(Collectors.toCollection(ArrayList::new));