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));