I am studying for a final, and im looking at a question from my midterm that i got wrong and honestly wasnt sure how to go about doing so. The question is as follows:
Rewrite the Person class so that if you have an ArrayList of Person objects, ArrayList, you can sort it using the Collections sort method. The sort method should sort the list first by decreasing age and then alphabetically (for people the same age).
The same code (Person class) that was provided in the question is below.
public class Person {
public String name;
public int age;
}
This was a midterm question so I had to hand write the code. I am wondering what is the efficient and proper way to answer this question. All answers or input is greatly appreciated. Thanks.