DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Sort An Array Of File By Modification Date Descending
File f = new File(path);
File [] files = f.listFiles();
Arrays.sort( files, new Comparator()
{
public int compare(Object o1, Object o2) {
if (((File)o1).lastModified() > ((File)o2).lastModified()) {
return -1;
} else if (((File)o1).lastModified() < ((File)o2).lastModified()) {
return +1;
} else {
return 0;
}
}
});






Comments
Snippets Manager replied on Mon, 2012/05/07 - 2:13pm
Snippets Manager replied on Mon, 2012/05/07 - 2:13pm
new Long(((File)o1).lastModified()).compareTo(new Long(((File) o2).lastModified());or with 1.5 autoboxing ((File)o1).lastModified().compareTo((File)o2).lastModified())