title: How to add item to an arraylist with object class in alphabetical order
body: <p>So I have a "Directory class", a "Person object class" and a text file of names somewhere in the folder. I have already converted the txt file and stored it into an arraylist under my "Directory class". I made a method inside my directory class to search for a name in that list. Now I have to make another method to ask the user to input a name to add into the arraylist, if its there already then an appropriate message pops up, if not then I have to add the name in the correct place (alphabetical order). I am having trouble doing that. My code for the search name method is this:`  </p>
  
  <pre><code>public int searchLastName(String lastName) {
      int i;
      boolean found = false;
      int index;
  
      i = 0;
      index = -1;
  
      while (i &lt; persons.size() &amp;&amp; !found) {
          if (lastName.equalsIgnoreCase (persons.get(i).getLastName())) {
              index = i;
              found = true;
          }
          i++;
      }
      return index;
  }
  </code></pre>
  
  <p>And the method to add is this so far...:`     </p>
  
  <pre><code>public void optionA() {
      Person one;
      String lastName;
      String firstName;
      String initial;
      String department;
  
      int telNum;
      int index;
      int size;
  
  
      System.out.println("Please enter a last name to add into directory");
      lastName = kbd.next();
      index = searchLastName(lastName);
  
      if (index &lt; 0) {
          System.out.println("Please enter first name");
          firstName = kbd.next();
  
          System.out.println("Please enter initial");
          initial = kbd.next();
  
          System.out.println("Please enter department");
          department = kbd.next();
  
          System.out.println("Please enter local phone number");
          telNum = kbd.nextInt();
  
          one = new Person(lastName, firstName, initial, department, telNum);
  
          persons.add(one);
  
      }
  
  }
  </code></pre>
  
  <p>This is the constructor for the Person object class: `}</p>
  
  <pre><code>public Person (String lastN, String firstN, String intl, String departm, int tel) {
      lastName = lastN;
      firstName = firstN;
      initial = intl;
      department = departm;
      telNum = tel;
  }
  </code></pre>
  
  <p>Please help I've been stuck on this for hours...</p>