While updating for loops to for-each loops in our application, I came across a lot of these "patterns":
for (int i = 0, n = a.length; i < n; i++) {
...
}
instead of
for (int i = 0; i < a.length; i++) {
...
}
I can see that you gain performance for collections because you don't need to call the size() method with each loop. But with arrays??
So the question arose: is array.length
more expensive than a regular variable?