I have a class
public class StudentVO {
int age;
String name;
}
I used the same class in two different areas. At one place i need t
Anton's approach is quite good. I use this one:
1- For sorting only by age:
Collections.sort( studentList, Comparator.comparingInt( student -> student.getAge() ) );
2- For name:
Collections.sort( studentList, Comparator.comparing( student -> student.getName() ) );
3- Combination:
Collections.sort( studentList, Comparator.comparing( student -> student.getName() ).thenComparingInt( student -> student.getAge() ) );