title: Merge sort returns an ArrayList comprised of multiple duplicates of the first entry rather than a sorted ArrayList
body: <p>Calling my Merge sort method on an <code>ArrayList</code> of data objects returns an <code>ArrayList</code> entirely comprised of the first entry in the original <code>ArrayList</code> (the original had 9k separate entries, while the 'sorted' one had 9k duplicates of the first entry of the original).</p>
  
  <p>I've gone over the code but can't seem to spot why. The function operates on an <code>ArrayList</code> of <code>JsonObject</code> from javax, and the sorting criteria is a field within said <code>JsonObject</code>. It's supposed to compare the strings of said field and sort them. </p>
  
  <pre><code>public void sortDataObjects(String identifier, ArrayList&lt;JsonObject&gt; both) {
      ArrayList&lt;JsonObject&gt; left = new ArrayList&lt;&gt;();
      ArrayList&lt;JsonObject&gt; right = new ArrayList&lt;&gt;();
      int size = both.size();
      int midpoint = size / 2;
  
      if (size == 1) {
          return;
      } else {
          for(int i = 0; i &lt; midpoint; i++) {
              left.add(both.get(i));
          }
          for (int i = midpoint; i &lt; size; i++) {
              right.add(both.get(1));
          }
  
          sortDataObjects(identifier, left);
          sortDataObjects(identifier, right);
  
          mergeSortHelper(identifier, left, right, both);
      }
  }
  
  public void mergeSortHelper(String identifier, ArrayList&lt;JsonObject&gt; left, ArrayList&lt;JsonObject&gt; right, ArrayList&lt;JsonObject&gt; both) {
      int leftIndex = 0;
      int rightIndex = 0;
      int bothIndex = 0;
  
      while (leftIndex &lt; left.size() &amp;&amp; rightIndex &lt; right.size()) {
          if ((left.get(leftIndex).getString(identifier).compareTo(right.get(rightIndex).getString(identifier))) &lt; 0) {
              both.set(bothIndex, left.get(leftIndex));
              leftIndex++;
          } else {
              both.set(bothIndex, right.get(rightIndex));
              rightIndex++;
          }
          bothIndex++;
      }
  
      if (leftIndex &gt;= left.size()) {
          // The left ArrayList has been use up...
          for (int i = rightIndex; i &lt; right.size(); i++) {
              both.set(bothIndex, right.get(i));
              bothIndex++;
          }
      } else {
          for (int i = leftIndex; i &lt; left.size(); i++) {
              both.set(bothIndex, left.get(i));
              bothIndex++;
          }
      }
  }
  </code></pre>