title: Selection Sort for strings and integers at the same time
body: <p>Here is the task I have been set with:</p>
  
  <p>Create a text file named Names_ages.txt with the following content:</p>
  
  <pre><code>Jones 14
  Abrams 15
  Smith 19
  Jones 9
  Alexander 22
  Smith 20
  Smith 17
  Tippurt 42
  Jones 2
  Herkman 12
  Jones 11
  </code></pre>
  
  <p>Each line is a person’s last name followed by a space and then his age. We want to sort these names alphabetically and in the case of duplicate names, sort by age in an ascending fashion. A properly sorted list will appear as follows:</p>
  
  <pre><code>Abrams, 15
  Alexander, 22
  Herkman, 12
  Jones, 2
  Jones, 9
  Jones, 11
  Jones, 14
  Smith, 17
  Smith, 19
  Smith, 20
  Tippurt, 42
  </code></pre>
  
  <p>Here are my (working) selection sort methods for Strings and ints respectively:</p>
  
  <pre><code>private static void sort(String[] a) {
  
      String min;
      int minIndex;
  
      for (int i = 0; i &lt; a.length; i++) {
          min = a[i];
          minIndex = i;
          // find minimum
          for (int j = i + 1; j &lt; a.length; j++) {
              // salient feature
              if (a[j].charAt(0) &lt; min.charAt(0)) {
                  min = a[j];
                  minIndex = j;
              }
          }
          a[minIndex] = a[i]; // swap
          a[i] = min;
      }
  
  }
  
  private static void sort(int[] a) {
  
      int min, minIndex;
  
      for (int i = 0; i &lt; a.length; i++) {
          min = a[i];
          minIndex = i;
          // find minimum
          for (int j = i + 1; j &lt; a.length; j++) {
              // salient feature
              if (a[j] &lt; min) {
                  min = a[j];
                  minIndex = j;
              }
          }
          a[minIndex] = a[i]; // swap
          a[i] = min;
      }
  
  } 
  </code></pre>
  
  <p>I can sort the names in the text file and then the numbers after, but the ages end up corresponding with incorrect people. Here is my class with the main method:</p>
  
  <pre><code>Scanner scanner = new Scanner(new File("/Users/Krish/IdeaProjects/Lessons/src/Lesson40/MultipleKey/NamesAges.txt"));
      String text[] = new String[100];
      int index = 0;
  
      while (scanner.hasNext()) {
          text[index++] = scanner.nextLine();
      }
  
      scanner.close();
  
      String name;
      String[] names = new String[index];
      int age;
      int[] ages = new int[index];
  
      for (int i = 0; i &lt; index; i++) {
          Scanner line = new Scanner(text[i]);
          name = line.next();
          names[i] = name;
          age = line.nextInt();
          ages[i] = age;
      }
  
      sort(names);
      sort(ages);
  
      for (int i = 0; i &lt; index; i++) {
          System.out.println(names[i] + ", " + ages[i]);
      }
  </code></pre>
  
  <p>Any help is appreciated, thanks.</p>