title: Java: Printing only the First and Last when the names that the user gave are organized alphabetically
body: <p>I am a bit lost on where I went wrong here is my main file: </p>
  
  <pre><code>import java.util.Scanner;
  import java.util.Arrays;
  import java.util.*; 
  import java.util.TreeSet; 
  
  public class personSorter 
  {
    public static void main(String[] args)
    {
    int count = 0; 
    Scanner in = new Scanner(System.in);
  
    boolean more = true;
    Person first = null;
    Person last = null; 
  
    Person[] people= new Person[10]; //my array 
  
    while(more)
    {
    System.out.println("Please enter the person's name or a blank line to quit");
    String names = in.nextLine(); 
  
    if (names.equals(""))
       {    
       more = false;
       }
   else
   {
          Person p1 = new Person(names);  //creating 10 person objects to be used
          Person p2 = new Person(names);
          Person p3 = new Person(names);
          Person p4 = new Person(names);
          Person p5 = new Person(names);
          Person p6 = new Person(names);
          Person p7 = new Person(names);
          Person p8 = new Person(names);
          Person p9 = new Person(names);
          Person p10 = new Person(names); 
  
         people[count] = p1; // using my person objects and declaring the index of variable count
         people[count] = p2;
         people[count] = p3;
         people[count] = p4;
         people[count] = p5;
         people[count] = p6;
         people[count] = p7;
         people[count] = p8;
         people[count] = p9;
         people[count] = p10;
  
          first = people[count];
          last  = people[count];
  
      TreeSet&lt;String&gt; treeSet = new TreeSet&lt;String&gt;(); //using TreeSort to get the names entered by user in ascending order
  
       treeSet.add(names);
       treeSet.add(names);
       treeSet.add(names);
       treeSet.add(names);
       treeSet.add(names);
       treeSet.add(names);
       treeSet.add(names);
       treeSet.add(names);
       treeSet.add(names);
       treeSet.add(names);
  
  
  
     first.compareTo(p1); //after TreeSort first compare method called of first object as it is now the first name in alphabet order
     last.compareTo(p10); //after TreeSort last compare method called of last object as it is now the last name in alphabet order
  
    count++;       
    }
  }
  
  //printing out the first and last name(in alphabet order) of the entered names 
    System.out.println("First: " + first.toString()); 
    System.out.println("Last: " + last.toString());
   } 
   }
  </code></pre>
  
  <p>I used a TreeSet to arrange the names in alphabet order. Then I used the call to compareTo method on object 1 and 10 only because when they are arranged in alphabet order the first object becomes the first name and the last object becomes the last name. </p>
  
  <p>Here is the Person.java:</p>
  
  <pre><code>public class Person implements Comparable &lt;Person&gt; 
      {
          private String name;
  
  public Person(String n) 
  {
      name = n;
  }
  
  public String getName() 
  {
      return name;
  }
  
     @Override
  public int compareTo(Person others) 
  {
      if (name.compareTo(others.name) == 1) 
      {
          return 0;
      } 
      else if (name.compareTo(others.name) &lt; 0) 
      {
          return -1;
      } 
      else 
      {
          return 1;
      }
     }
     public String toString() 
     {
     return "[" + name + "]";
     }
  
  }
  </code></pre>
  
  <p>However, the final output is all the names entered by the user in the order they inputted it. As in, the names weren't even in alphabet order. Any help would be much appreciated it!</p>