I'm wondering if the JVM is able to hoist a stream out of a loop, for example in this intersection check that I wrote:
for (SomeObject someObject:someObjects) {
if (someList.stream().map(SomeObject::getValue).collect(Collectors.toList())
.contains(someObject.getValue())) {
//do some error stuff
}
}
Is it necessary for me to refactor it like so:
final List<Value> values = someList.stream().map(SomeObject::getValue).collect(Collectors.toList());
for (SomeObject someObject:someObjects) {
if (values.contains(someObject.getValue()) {
//do some error stuff
}
}
It's probably nicer looking code this way, but I'm just wondering if it will have a big performance difference.