I have a class with two date fields say:
class TestData {
Date activation;
Date timeStamp;
}
I want to sort the list of the above class on basis of activation
date and if they are equal then on basis of timestamp
i.e. max(activation) and max(timeStamp).
Code I tried is as follws which only fetch max(activation)
public class CollectionSort {
public static void main(String[] args) {
List<TestData> testList = new ArrayList<TestData>();
Collections.sort(testList, new Comparator<TestData>() {
@Override
public int compare(TestData t1, TestData t2) {
int result = 0;
if (t1.getActivation().before(t2.getActivation())) {
result = 1;
}
return result;
}
});
System.out.println("First object is " + testList.get(0));
}
}
Any help would be greatly appreciated.
Thanks