title: Delete every nth element from list Java ArrayList vs LinkedList
body: <p>So I wanted to test ArrayList vs LinkedList <code>remove()</code> method times just for fun.</p>
  
  <p>I wrote code below to do it - everything is pretty self-explanatory: <code>deleteEachNth</code> runs through my list and deletes every nth element it sees.</p>
  
  <p>I was expecting to see LinkedList winning by a huge margin, as its remove times are constant-time operations, but my code produces opposite results: for 10000 elements ArrayList is twice as fast.</p>
  
  <p>Naturally, I thought I'd written something wrong, perhaps used a <code>get()</code>, which would slow LinkedList down somewhere, but it isn't the case.</p>
  
  <p>Whats wrong  here?</p>
  
  <p>EDIT: When replacing <code>System.currentTimeInMillis()</code> with <code>System.nanoTime()</code> LinkedList still performs worse for my code. </p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.LinkedList;
  import java.util.List;
  import java.util.stream.IntStream;
  
  public class Test{
      List&lt;String&gt; myList;
      Test(List&lt;String&gt; someList){
          myList = someList;
      }
      void eliminateEachNth(int n){
          for (int i = 1; i &lt; myList.size(); i++) {
              if(i%(n-1)==0){
                  myList.remove(i);
              }
          }
      }
      public static void main(String[] args){
          List&lt;String&gt; someList = new ArrayList&lt;&gt;();
          IntStream.range(1, 10000).forEach(i-&gt;someList.add(Integer.toString(i)));
          Test testArray = new Test(someList);
          long cur = System.currentTimeMillis();
          testArray.eliminateEachNth(3);
          System.out.println("array list took " + (System.currentTimeMillis() - cur) + "millis");
          System.out.println(someList);
          List&lt;String&gt; anotherList = new LinkedList&lt;&gt;();
          IntStream.range(1, 10000).forEach(i-&gt;anotherList.add(Integer.toString(i)));
          Test testLinked = new Test(anotherList);
          cur = System.currentTimeMillis();
          testLinked.eliminateEachNth(3);
          System.out.println("linked list took " + (System.currentTimeMillis() - cur) + "millis");
          System.out.println(anotherList);
  
      }
  }
  </code></pre>