title: How to sort a List of Persons by first name, last name and so on?
body: <p>I'm prompting the user to enter his first name, last name and age.<br>
  I use a confirm dialog to ask user if he want's to add another person then I display the names that he entered. </p>
  
  <p>How can I sort the persons by first name, second name and so on ?</p>
  
  <pre><code>public static void main(String[] args) {
  
      ArrayList&lt;Person&gt; list = new ArrayList();
      int i = 0;
      while (i == 0) {
  
          Person p = new Person();
  
          String fname = JOptionPane.showInputDialog("Enter First Name ");
          String lname = JOptionPane.showInputDialog("Enter Last Name ");
          int Age = Integer.parseInt(JOptionPane.showInputDialog("Enter your Age "));
  
          p.setfName(fname);
          p.setLname(lname);
          p.setAge(Age);
  
          list.add(p);
  
  
   i=JOptionPane.showConfirmDialog(null, "Are you Want to Add other person","Confirmation",2);
  
      }
  
      for (int j = 0; j &lt; list.size(); j++) {
          System.out.print("First name : "+list.get(j).getfName()+"\t Last Name : " + list.get(j).getLname()+"\t Age : "+list.get(j).getAge());
      list.equals(j);
  
          System.out.print("\n------------------------ \n ");
  }
  
  public class Person{
  
      private String fName;
      private String lname;
      private int age;
  
      public Person() {
  
      }
  
      public Person(String fName, String lname, int age) {
          this.fName = fName;
          this.lname = lname;
          this.age = age;
      }
  
      public String getfName() {
          return fName;
      }
  
      public void setfName(String fName) {
          this.fName = fName;
      }
  
      public String getLname() {
          return lname;
      }
  
      public void setLname(String lname) {
          this.lname = lname;
      }
  
      public int getAge() {
          return age;
      }
  
      public void setAge(int age) {
          this.age = age;
      }
  
  
  }
  </code></pre>