title: What is the runtime of array.length?
body: <p>Let's say I have an array:</p>
  
  <pre><code>int[] array = new int[10];
  </code></pre>
  
  <p>What is the runtime of:</p>
  
  <pre><code>int len = array.length;
  </code></pre>
  
  <p>I would think that this would be a constant time operations, but today in an interview, the interviewer told me that this would be <code>O(n)</code> because the number of elements would need to be counted.</p>
  
  <p>Additionally, if I have a loop like this:</p>
  
  <pre><code>for (int i = array.length - 1; i &gt;=0; i--) {
      something with array[i];
  }
  </code></pre>
  
  <p>Does this entail an extra <code>n</code> operations to get to the end of the array to start the loop?  The interviewer came from a C background, so maybe they were mistaken about how Java works, but I didn't want to push it during the interview.</p>