title: How to sort an ArrayList by a users last name
body: <p>How do I sort an <code>ArrayList</code> by a users last name? My program prints out the names in order by first name. Is there another <code>collections.sort(..);</code> method? Or a way without making a map.</p>
  
  <pre><code>public static void main(String[] args) throws FileNotFoundException {
      String check = "y";
      do {
          Scanner fileRead = new Scanner(System.in);
          System.out.println("Enter the name of the file: ");
          File myFile = new File(fileRead.next());
          ArrayList&lt;String&gt; names = new ArrayList&lt;&gt;();
  
          Scanner scanTwo = new Scanner(myFile);
  
          while (scanTwo.hasNextLine()) {
              names.add(scanTwo.nextLine());
          }
          Collections.sort(names);
          for (String name : names) {
              System.out.println(name);
          }
  
          System.out.println();
          Scanner ans = new Scanner(System.in);
          System.out.println("Add another? y/n ");
          check = ans.next();
      } while (check.equals("y"));
  } 
  </code></pre>