gpt4 book ai didi

java - 在 Java 流 : combine filters or combine circumstances? 的性能方面有什么更好的

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:33:01 32 4
gpt4 key购买 nike

<分区>

需要过滤所有适合其领域某些情况的对象。假设对象有几个字段:

class Price {
int first;
int second;
String third;
}

和价格流:

Stream<Price> streamPrices; 

什么是最好的选择:

1.

streamPrices
.parallel()
.filter(p0->p0.first> 10)
.filter(p1->p1.second <30)
.filter(p2-> p2.third.length() > 8);

2.

streamPrices
.parallel()
.filter(p-> (p.first > 10)
&& (p->p.second <30)
&& (p-> p.third.length() > 8)
);

我使用了JMH框架,但没有得出明确的结论。

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com