The following sample code is from Internet, I hope to sort the List<String> files by filename at ascending or descending.
I hope to the List<String> files by date of file at ascending or descending, how can I do ? Thanks!
The same quetsion with List<String> directories.
List<String> files = Arrays.asList(f.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
File f=new File(dir, name);
return f.isFile()&&(f.isHidden()==false);
}
}));
Collections.sort(files);
List<String> directories = Arrays.asList(f.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
File f=new File(dir, name);
return f.isDirectory()&& (f.isHidden()==false);
}
}));
Collections.sort(directories);
Just provide your File array and it sort simple.
Demo: