title: Guarantee the order of Array processing .each() Groovy
body: <p>In groovy I know that the .each() loop on a Map has <a href="http://groovy.codehaus.org/groovy-jdk/java/util/Map.html#each" rel="nofollow">no guarantee</a> of the order of when contents are processed. What about the .each() on an Array of objs? My thoughts were that the .each() on an array would safely give me the expected order every time, but talking with a friend the other day, he said he doesn't think the order will be guaranteed. For example:</p>
  
  <pre><code>MyObj[] x = [ obj1, obj2, obj3 ];
  
  x.each(){ obj -&gt;
    //what order will my objs come in?
  }
  </code></pre>
  
  <p>Also, what about: </p>
  
  <pre><code>x.eachWithIndex() { obj, i -&gt;
    println(i); //what order will they come in?
  }
  </code></pre>
  
  <p>Can I guarantee the order of my .each() or .eachWithIndex() loop?</p>
  
  <p><a href="http://groovy.codehaus.org/Looping" rel="nofollow">Reference</a></p>