title: JAVA: How to sort strings read from file and output to console in alphabetical order?
body: <p>I'm looking to sort the contacts read from a file in alphabetical order by last name to the console? How would I go about doing so? The contacts are already written to file starting with the last name, I just want to read them back into the application in alphabetical order when a user wants to view the contacts in the console.</p>
  
  <pre><code>// Read from file, print to console. by XXXXX
              // ----------------------------------------------------------
              int counter = 0;
              String line = null;
  
              // Location of file to read
              File file = new File("contactlist.csv");
  
              try {
  
                  Scanner scanner = new Scanner(file);
  
                  while (scanner.hasNextLine()) {
                      line = scanner.nextLine();
                      System.out.println(line);
                      counter++;
                  }
                  scanner.close();
              } catch (FileNotFoundException e) {
  
              }
              System.out.println("\n" + counter + " contacts in records.");
  
          }
          break;
          // ----------------------------------------------------------
          // End read file to console. by XXXX
  </code></pre>