title: Having the user search a text file inside an array for a name, and then printing the shortest and longest names in the file
body: <p>The code I'm writing is to have the user search a name in a text file and, if the name is found in the file, then the program will output "Name found."</p>
  
  <p>Then I just need the program to output the shortest and longest name in the file which is plainly something I have no idea how to do. This is what I have so far and I just can't get it to work.</p>
  
  <p>Just want to be clear that programming is not my strong suit so my code may be a little sloppy. Any help would be greatly appreciated.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  
  public class Homework11 {
      public static void main(String args[]) throws IOException {
  
          Scanner fileScan = new Scanner(new File("names.txt"));
          Scanner keyboard = new Scanner(System.in);
  
          // resets the Scanner to look for commas as
          // the separator between the color names
          fileScan.useDelimiter(",");
  
          // initial capacity by default is 10 items
          ArrayList&lt;String&gt; names = new ArrayList&lt;String&gt;();
  
          while (fileScan.hasNext()) {
  
              // each color read from the file is added to the ArrayList
              names.add(fileScan.next());
          }
  
          // dump all the color names into a standard array of Strings
          String namesArray[] = names.toArray(new String[0]);
  
          // sort the color array into alphabetical order
          Arrays.sort(namesArray);
  
          for (int i = 0; i &lt; namesArray.length; i++) {
  
              // copy the array values back, overwriting the ArrayList
              names.set(i, namesArray[i]);
          }
  
          System.out.println("Please enter a name to search.");
          String input = keyboard.next();
          String x = input.toUpperCase();
          if (names.contains(x)) {
              System.out.println("Name Found.");
          }
      }
  }
  </code></pre>