title: How to merge two strings alphabetically?
body: <p>Beginner here.
  I am trying to merge to strings in alphabetical order using the <code>compareTo</code> method, but my <code>fullfirstarray[i] = arrayone[i];</code> and <code>fullsecondarray[i] = arraytwo[i];</code> lines as well as my final black of code are giving me errors, mostly OutofBoundsExceptions</p>
  
  <pre><code>`import java.util.Scanner;
  import java.lang.Math; 
  
  
  class NamesMerge
  {
  public static void main(String[] args)
   {
    Scanner scan = new Scanner (System.in); 
  
    int flag = 0;
    int i = 0;
    String name = "";
    String input = "";
    int firstcounter = 0;
    int secondcounter = 0;
  
    String[] fullfirstarray = new String[firstcounter];
    String[] fullsecondarray = new String[secondcounter];
  
    System.out.println("Enter the values for the first array, up to 10000 values, enter 'End' to quit");
  
    //first array prompt (arrayone)
    String[] arrayone = new String[10000];
  
      input = scan.nextLine();
  
      input = input.toLowerCase();
      input = input.substring(0, 1).toUpperCase() + input.substring(1);
  
    while (!(input.equals("End")))
    {
      System.out.println(input);
      arrayone[i] = input;
          i++;
      input = scan.nextLine();
      input = input.toLowerCase();
      input = input.substring(0, 1).toUpperCase() + input.substring(1);
    }
  
    if (input.equals("End"))
    {
      System.out.println("Enter the values for the second array, up to 10000 values, enter 'End' to quit");
    }
  
    //next array prompt (arraytwo)
    String[] arraytwo = new String[10000];
  
      input = scan.nextLine();
      input = input.toLowerCase();
      input = input.substring(0, 1).toUpperCase() + input.substring(1);
  
    while (!(input.equals("End")))
    {
      System.out.println(input);
  
      arraytwo[i] = input;
          i++;
      input = scan.nextLine();
      input = input.toLowerCase();
      input = input.substring(0, 1).toUpperCase() + input.substring(1);    
    }
  
    //PRINTING THE FIRST ARRAY
    if (input.equals("End"))
    {
      System.out.println("First Array");
    }
  
  
    for (i =0; i &lt; arrayone.length; i++)
    {
      if  (arrayone[i]!=null)
      {
        System.out.print(arrayone[i] + " ");
               firstcounter++;  
        fullfirstarray[i] = arrayone[i];
      }
    }
  
    //PRINTING THE SECOND ARRAY
    System.out.println("\nSecond Array");
  
    for (i =0; i &lt; arraytwo.length; i++)
    {
      if  (arraytwo[i]!=null)
      {
        System.out.print(arraytwo[i] + " ");
                secondcounter++; 
        fullsecondarray[i] = arraytwo[i];
      }
    }
  
  
    //counter for total names
    System.out.println(firstcounter);
    System.out.println(secondcounter);
  
  
    //merge
    String[] merge = new String[firstcounter + secondcounter];
  
    int arrayoneindex = 0; 
    int arraytwoindex = 0;
  
    for (i = 0; i &lt; (firstcounter + secondcounter); i++)
      if (fullfirstarray[i].compareTo(fullsecondarray[i])&lt;0)
      {
      merge[i] = fullfirstarray[i]; 
      arrayoneindex++;
      }
    else
      if (fullsecondarray[i].compareTo(fullfirstarray[i])&lt;0)
      {
        merge[i] = fullsecondarray[i];
        arraytwoindex++;
      }
    for (i = 0; i&lt;merge.length; i++)
      {
        System.out.print(merge[i]);
      }
      }
  
      }
  </code></pre>