title: Java for each vs regular for -- are they equivalent?
body: <p>Are these two constructs equivalent?</p>
  
  <pre><code>char[] arr = new char[5];
  for (char x : arr) {
      // code goes here
  }
  </code></pre>
  
  <p>Compared to:</p>
  
  <pre><code>char[] arr = new char[5];
  for (int i = 0; i &lt; arr.length; i++) {
      char x = arr[i];
      // code goes here
  }
  </code></pre>
  
  <p>That is, <strong>if I put exactly the same code in the body of both loops (and they compile), will they behave exactly the same???</strong></p>
  
  <hr>
  
  <p>Full disclaimer: this was inspired by another question (<a href="https://stackoverflow.com/questions/2422320/java-are-these-2-codes-the-same">Java: are these 2 codes the same</a>). My answer there turned out not to be the answer, but I feel that the exact semantics of Java for-each has some nuances that needs pointing out.</p>