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