title: How To Split an Array in half in java
body: <p>I need to split this array after it is sorted so that it prints something like</p>
  
  <p>A: [8, 7, 6, 5]</p>
  
  <p>B: [4, 3, 2, 1]</p>
  
  <p>I know it might be simple but I cant figure it out. Do I need to do something like x.length / 2 ?</p>
  
  <pre><code> import java.util.Arrays;
  
  
  public class RecursiveMerge
  {
  
  public static void main(String[] args) {
      // TODO Auto-generated method stub
      int [] x= {8,7,5,6,2,4,3,1};
      System.out.println(Arrays.toString(x));
      System.out.println(Arrays.toString(mergeSort(x)));
  
  
  
  }
  
  public static int [] mergeSort (int []a)
  {
      if(a.length ==1)
          return a;
      else
      {
      int mid =  a.length/2;
      int [] left =mergeSort(Arrays.copyOfRange(a, 0 , mid ));
      int [] right =mergeSort(Arrays.copyOfRange(a, mid, a.length ));
  
      mergeSort(left);
      mergeSort(right);
  
      return merge (left, right);
      }
  }
  public static int[] merge (int[] left, int[] right)
  {
  int [] result = new int [left.length + right.length];
  
  int leftPtr=0, rightPtr=0, resultPtr=0;
  
  
  while(leftPtr &lt; left.length &amp;&amp; rightPtr &lt; right.length)
      if (left[leftPtr] &lt; right [rightPtr])
          result[resultPtr++] = left[leftPtr++];
      else
          result[resultPtr++] = right[rightPtr++];
  while (leftPtr &lt; left.length)
      result[resultPtr++] = left[leftPtr++];
  while (rightPtr &lt;right.length)
      result[resultPtr++] = right[rightPtr++];
  return result;
  
  }
  }
  </code></pre>