Skip to content

Instantly share code, notes, and snippets.

@shaobin0604
Created February 20, 2013 03:17
Show Gist options
  • Select an option

  • Save shaobin0604/4992547 to your computer and use it in GitHub Desktop.

Select an option

Save shaobin0604/4992547 to your computer and use it in GitHub Desktop.
private static final Comparator<File> FILE_COMPARATOR = new Comparator<File>() {
@Override
public int compare(File lhs, File rhs) {
boolean ldir = lhs.isDirectory();
boolean rdir = rhs.isDirectory();
if (ldir == rdir) {
// both are files or directories
return lhs.getName().compareToIgnoreCase(rhs.getName());
} else if (ldir) {
return -1;
} else {
return 1;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment