To compare Strings containing timestamps you need to first parse them to long Long.parseLong(timestamp)
and then compare numeric value using Long.compare(x,y)
.
So try maybe with Collections.sort(yorList, yourOwnComparator)
like
Collections.sort(temp, new Comparator<SMS>() {
@Override
public int compare(SMS o1, SMS o2) {
return Long.compare(Long.parseLong(o1.timestamp),
Long.parseLong(o2.timestamp));
}
});
If you can change type of timestamp to long
this code could look like
Collections.sort(temp, new Comparator<SMS>() {
@Override
public int compare(SMS o1, SMS o2) {
return Long.compare(o1.timestamp, o2.timestamp);
}
});
In Java8 you can even use lambdas to shorten code even more
Collections.sort(temp, (SMS o1, SMS o2) -> Long.compare(o1.timestamp, o2.timestamp));
or even
Collections.sort(temp, (o1, o2) -> Long.compare(o1.timestamp, o2.timestamp));