title: Is This The Best Way To "Increase" The Size of An ArrayList?
body: <pre><code>ArrayList&lt;T&gt; tempArray = new ArrayList&lt;&gt;(size);
  </code></pre>
  
  <p>I was building a tempArray for my merge sort that will either sort integers or Strings depending on the context. Hence the type T ArrayList.</p>
  
  <p>Then all the sudden I kept running into IndexOutOfBounds errors whenever this was called:</p>
  
  <pre><code>tempArray.set(index, values.get(leftFirst));
  </code></pre>
  
  <p>After some research I discovered capacity and size don't mean the same thing. So in order to "increase" the size I just added a for loop that runs for size times that adds a null each time:</p>
  
  <pre><code>for (int i = 0; i &lt; size; i++)
      tempArray.add(null);
  </code></pre>
  
  <p>Is this the best solution?</p>