title: How to use recursion to sort an array of strings from smallest to largest?
body: <pre><code>import java.io.File;
  import java.util.Scanner;
  
  public class TestDriver {
  
  public static void main(String[] args) {
      Scanner x = null;
      try {
          x = new Scanner(new File("pokemon"));
      } catch (Exception e) {
          System.out.println("could not find file");
      }
  
      @SuppressWarnings("resource")
      Scanner input = new Scanner(System.in);
      System.out.println("Type in the number of Pokemons (1-15)!");
      int userNumber = 0;
      boolean userFalse = false;
      while (!userFalse) { // Validates user inputs for years
          if (input.hasNextInt()) {
              int temp = input.nextInt();
              if (temp &lt; 1 || temp &gt; 15) { // Years cannot be below 0
                  System.out.println("Invalid input.");
                  userFalse = false;
              } else {
                  userFalse = true;
                  userNumber = temp;
              }
          } else {
              System.out.println("Try Again!");
              input.next();
          }
      }
      String[] a = new String[userNumber];
      for (int i = 0; i &lt; userNumber; i++) {
          a[i] = x.next();
          System.out.print(a[i] + " ");
      }
      sort(a, userNumber);
  }
  </code></pre>
  
  <p>In the pokemon.txt, it reads</p>
  
  <pre><code>Gyarados  
  Lapras 
  Eevee  
  Vaporeon 
  Snorlax
  Abra
  Slowbro
  Rhyson
  Kyogre
  Blastoise
  Jigglypuff
  Miltank
  Lugia
  Steelix
  Arbok
  </code></pre>
  
  <p>I am trying to sort the Pokemon NAMES from smallest to largest. I don't know the best way to do this. My teacher wants me to do it using recursion. Is that the same thing as quicksort or mergesort? Thanks in advance.
  edit: Here's my attempt to sort using mergesort:</p>
  
  <pre><code>public static void sort(String[] pokemon, int userNumber) {
  
      String[] a = new String[pokemon.length / 2]; // Split array into two
      String[] b = new String[pokemon.length - a.length]; // halves, a and b
      for (int i = 0; i &lt; pokemon.length; i++) {
          if (i &lt; a.length)
              a[i] = a[i];
          else
              b[i - a.length] = pokemon[i];
      }
  
      sort(a, userNumber); // Recursively sort first
      sort(b, userNumber); // and second half.
  
      int ai = 0; // Merge halves: ai, bi
      int bi = 0; // track position in
      while (ai + bi &lt; pokemon.length) { // in each half.
          if (bi &gt;= b.length || (ai &lt; a.length &amp;&amp; a[ai].length() &lt; b[bi].length())) {
              pokemon[ai + bi] = a[ai]; // (copy element of first array over)
              ai++;
          } else {
              pokemon[ai + bi] = b[bi]; // (copy element of second array over)
              bi++;
          }
      }
  }
  </code></pre>