title: Merge Sort names alphabetically not working
body: <p>So I'm trying to sort names from a file alphabetically but it's not giving me the correct output. When entering 5 items, the output should be:</p>
  
  <p>British Virgin Islands, Hong Kong, Luxembourg, Maldives, New Zealand</p>
  
  <p>instead it gives an incorrect output of:</p>
  
  <p>Luxembourg, New Zealand, Maldives, New Zealand, Luxembourg</p>
  
  <p>NOTE: The starting index is index 1, instead of index 0</p>
  
  <pre><code>        import java.io.*;
          import java.io.BufferedReader;
          import java.io.IOException;
          import java.util.Scanner;
          public class triall
          {
             public static void main(String[] args)
                {
                Scanner sc = new Scanner (System.in);
                  Scanner in = new Scanner (System.in);
                  System.out.print("Enter maximum number of items: ");
                  int num = sc.nextInt();
                  String [] arr1 = new String [num+1];
                  //String [] arr2 = new String [num+1]; 
                  String sLine = "";
                  int i;
  
                  try 
                  { 
                      FileInputStream fstream = new FileInputStream("ioc.txt");
                      BufferedReader bin = new BufferedReader(new InputStreamReader(fstream));
                      System.out.format("%-10s%-30s%-30s", "Index", "Array 1", "Array 2");
                      System.out.println("");
                      for ( i = 1; sLine  != null &amp;&amp; i &lt;= num; i++)
                      {
                          sLine = bin.readLine();
                          arr1[i] = sLine;
                          arr2[i] = sLine;
                          if (sLine == null)
                              System.out.println("EOF");
                          else
                          {   System.out.format("%-10d", i);
                              System.out.format("%-30s", arr1[i]);
                              System.out.format("%-30s\n", arr2[i]);
                          }    
                      }
  
                      sort (arr1);
  
                  } // end try
  
                  catch (IOException e) 
                  {
                      e.printStackTrace();
                  }
             }
  
  
                public static void merge(String[] a, int from,  int mid, int to)
                {  int n1 = (mid - from + 1);
                   int n2 = to - mid;
                      // size of the range to be merged
  
  
                   String[] left = new String[n1 + 1];
                   String [] right = new String[n2 + 1];
                   int i = 1;
                   while ( i &lt;= n1)
                   {
                       left [i] = a[from + i - 1];
                   }
  
                   int j = 1;
                   while (j &lt;= n2)
                   {
                       right [j] = a[mid + j];
                   }
  
                   i = 1;
                   j = 1;
                   int k = from;
  
                   while (k &lt;= to)
                   {
                       if (left[i].compareToIgnoreCase(right[j]) &lt;= 0)
                       {
                           a[k] = left[i];
                           i++;
                       }
                       else
                       {
                           a[k] = right[j];
                           j++;
                       }
                   }
  
                   for (i=1; i&lt;=to; i++)
                          System.out.println(a[i]);
                }
  
  
                public static void mergeSort(String [] a, int from, int to)
                {  if (from &lt; to)
                {int mid = (int) (Math.floor((from + to) / 2));
                    // sort the first and the second half
                   mergeSort(a, from, mid);
                   mergeSort(a, mid + 1, to);
                   merge(a, from, mid, to);}
                }
  
  
                public static void sort(String[] a)
                {  mergeSort(a, 1, a.length - 1);
             }
          }
  </code></pre>