I have an ArrayList in Java with a huge amount of files (~40.000 files). I need to sort these files ascending/descending by their date. Currently, I use a simple
Collections.sort(fileList, new FileDateComparator());
where FileDateComparator is
public class FileDateComparator implements Comparator<File>
{
@Override
public int compare(File o1, File o2)
{
if(o1.lastModified() < o2.lastModified())
return -1;
if(o1.lastModified()==o2.lastModified())
return 0;
return 1;
}
}
Sorting takes up up a too long time for me, like 20 seconds or more. Is there a more efficient way to realize this? I already tried Apache I/O LastModifiedFileComparator as comparator, but it seems to be implemented the same way, since it takes the same time.