private void merge(ArrayList<String> first, ArrayList<String> second)
   {  
      int iFirst = 0; // Next element to consider in the first array
      int iSecond = 0; // Next element to consider in the second array
      int j = 0; // Next open position in a

      // As long as neither iFirst nor iSecond is past the end, move
      // the smaller element into a
      while (iFirst < first.size() && iSecond < second.size()){  
         if (first.get(iFirst).compareTo(second.get(iSecond)) < 0){  
            a.set(j, first.get(iFirst));
            iFirst++;
         }
         else{  
            a.set(j, second.get(iSecond));
            iSecond++;
         }
         j++;
      }

      // Note that only one of the two loops below copies entries
      // Copy any remaining entries of the first array
      while (iFirst < first.size()) { 
         a.set(j, first.get(iFirst));
         iFirst++; j++;
      }
      // Copy any remaining entries of the second half
      while (iSecond < second.size()) { 
         a.set(j, second.get(iSecond));
         iSecond++; j++;
      }
   }