When I request object summaries from S3 via amazonS3Client.listObjects()
, the list is returned in key alphabetical order.
Does anyone know how to get S3 to return the objects in date (lastModified) order, so the newest objects are returned first?
Thanks.
Just sort the list after
Java 8
s3ObjectSummaries.sort(Comparator.comparing(S3ObjectSummary::getLastModified));
Before
Collections.sort(s3ObjectSummaries, new Comparator<S3ObjectSummary>() {
public int compare(S3ObjectSummary o1, S3ObjectSummary o2) {
return o1.getLastModified().compareTo(o2.getLastModified());
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With