As you might know a TreeSet will always have a sorted order
Solution
public class Student implements Comparable<Student> {
   String name;
    String address;
    int age;
   /**
    * @param name
    * @param address
    * @param age
    */
    public Student(String name, String address, int age) {
        this.name = name;
        this.address = address;
        this.age = age;
    }
   /**
    * @return the name
    */
    public String getName() {
        return name;
    }
   /**
    * @param name
    * the name to set
    */
    public void setName(String name) {
        this.name = name;
    }
   /**
    * @return the address
    */
    public String getAddress() {
        return address;
    }
   /**
    * @param address
    * the address to set
    */
    public void setAddress(String address) {
        this.address = address;
    }
   /**
    * @return the age
    */
    public int getAge() {
        return age;
    }
   /**
    * @param age
    * the age to set
    */
    public void setAge(int age) {
        this.age = age;
    }
   /*
    * (non-Javadoc)
    *
    * @see java.lang.Object#toString()
    */
    @Override
    public String toString() {
        return \"Student [name=\" + name + \", address=\" + address + \", age=\"
                + age + \"]\";
    }
   /*
    * (non-Javadoc)
    *
    * @see java.lang.Comparable#compareTo(java.lang.Object)
    */
    @Override
    public int compareTo(Student obj) {
        if (this.getAge() == obj.getAge())
            return 0;
        else
       if (this.getAge() < obj.getAge())
            return 1;
        else
            return -1;
}
}
 import java.util.Iterator;
 import java.util.TreeSet;
public class TestStudent {
public static void main(String[] args) {
       TreeSet<Student> students = new TreeSet<Student>();
        Student student1 = new Student(\"Srinivas\", \"VSKP\", 24);
        Student student2 = new Student(\"Kumar\", \"HYD\", 23);
        Student student3 = new Student(\"Kishore\", \"BNGLR\", 25);
        Student student4 = new Student(\"Rajesh\", \"CHENNAI\", 45);
       students.add(student1);
        students.add(student2);
        students.add(student3);
        students.add(student4);
       Iterator<Student> iterator = students.iterator();
        while (iterator.hasNext()) {
            Student student = iterator.next();
            System.out.println(student);
}
   }
 }
OUTPUT:
Student [name=Rajesh, address=CHENNAI, age=45]
 Student [name=Kishore, address=BNGLR, age=25]
 Student [name=Srinivas, address=VSKP, age=24]
 Student [name=Kumar, address=HYD, age=23]



