title: How to remove everything from an ArrayList in Java but the first element
body: <p>I am new to java programming, been programing in php so I'm used to this type of loop:</p>
  
  <pre><code>int size = mapOverlays.size();
  for(int n=1;n&lt;size;n++)
  {
      mapOverlays.remove(n);
  }
  </code></pre>
  
  <p>So I want to remove everything but the first item, so why doesn't this work? As I get it, after removal, array keys are rearranged or not?</p>