IntelliJ IDEA recommended to me just now to replace the following for-each loop with a Java 8 "forEach" call:
for (Object o : objects) {
if (o instanceof SomeObject) {
doSomething();
}
}
The recommended call would like like this:
objects.stream().filter(o -> o instanceof SomeObject).forEach(o -> doSomething());
Unless I'm misunderstanding how the underlying functionality of Stream works, it seems to me like using stream is an O(2n) operation as opposed to an O(n) operation for the standard for-each loop.