Consider the following list with Pojo
Object:
List<Pojo> list = new ArrayList<>();
....
class Pojo {
private int field1;
private int field2;
...
}
Note: Pojo can have more than two fields
I'm sorting my list of Pojo-s
by ascending order:
Collections.sort(list, new Comparator<Pojo>() {
@Override
public int compare(Pojo o1, Pojo o2) {
int fieldCompareTo = compare(o1.field1, o2.field1);
if (fieldCompareTo == 0) {
fieldCompareTo = compare(o1.field2, o2.field2);
}
return fieldCompareTo;
}
});
private static int compare(int a, int b) {
return a < b ? -1
: a > b ? 1
: 0;
}
Here I'll get list sorted by ascending order.
My Questions is: If I reverse the list, will I get descending order?
I'm just calling Collections.reverse(list)