I have objects
Person{
String name;
int age;
float gradeAverage;
}
Is there an easy way to sort
Person[]
You can implement the Comparable interface to make your class comparable. Make sure to override the compareTo method then.
public class Person implements Comparable {
String name;
int age;
float gradeAverage;
@Override
public int compareTo(Person p) {
if(this.age < p.getAge()) return -1;
if(this.age == p.getAge()) return 0;
//if(this.age > p.getAge()) return 1;
else return 1;
}
//also add a getter here
}