title: ArrayList sorting on the basis of object property
body: <p>The following is the Employee bean class.</p>
  
  <pre><code>public class Employee {
      public String name;
      public int age;
  
      public Employee()
      {
  
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public int getAge()
      {
          return age;
      }
  
      public void setAge(int age)
      {
          this.age = age;
      }
  }
  </code></pre>
  
  <p>I have other EmployeeTest class and inside it I create the object of the Employee class and store in a ArrayList.</p>
  
  <pre><code>import java.util.ArrayList;
  
  public class EmployeeTest {
      public static void main(String[] args) 
      {
          ArrayList&lt;Employee&gt; empList = new ArrayList&lt;Employee&gt;();
          Employee emp1 = new Employee();
          emp1.setAge(15);
          emp1.setName("Employee1");
          Employee emp2 = new Employee();
          emp2.setAge(10);
          emp2.setName("Employee1");
          empList.add(emp1);
          empList.add(emp2);
          for(Employee emp : empList)
          {
              System.out.println("employee name : " + emp.getName());
              System.out.println("employee age : " + emp.getAge());
          }
      }
  }
  </code></pre>
  
  <p>Now I have one question regarding it is that I want to sort ArrayList on the basis of Employee class age property. So please explain how can I sort it. </p>