I have a Member
class like this :
public class Member {
private int value1;
private boolean value2;
}
And an ArrayList<Member>
containing this data :
value1 - value2
- 1 - false
- 2 - false
- 3 - true
- 4 - false
- 5 - true
Now I want this data sorted this way :
- The members with
value2
as true must be returned first, then the other ones after - In each sublist, members will be returned from the highest to the lowest
value1
So in the end, the list should contain data in this order : 5, 3, 4, 2, 1.
I know that I can use Collections.sort()
to sort data by value1 :
Collections.sort(memberList, new Comparator<Member>(){
public int compare(Member m1, Member m2){
return m1.getValue1() - m2.getValue1();
}
});
But is there a way to sort data by both criterias in the same compare
method?
Thanks for your help.