According to thisfor is pretty much always faster than forEach, so if performance is more important than concise code (and it usually should be) a for loop is likely a better choice.
Correct, as the forEach call will incur a penalty invoking the lambda expression. forEach could have equivalent performance if the JIT inlines the lamba method body, but it's safe to say always expect forEach to be a bit slower.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
According to this
for
is pretty much always faster thanforEach
, so if performance is more important than concise code (and it usually should be) afor
loop is likely a better choice.Correct, as the
forEach
call will incur a penalty invoking the lambda expression.forEach
could have equivalent performance if the JIT inlines the lamba method body, but it's safe to say always expectforEach
to be a bit slower.