sortFilesWithDescending(File [] files)


/ Published in: Java
Save to your folder(s)

Sort a File array with the descending of file name.


Copy this code and paste it in your HTML
  1. import java.util.Arrays;
  2. import java.util.Comparator;
  3. import java.io.File;
  4.  
  5. void sortFilesWtihDescending(File[] files) {
  6. Arrays.sort(files, new Comparator<Object>() {
  7. public int compare(Object sa, Object sb) {
  8. File f1 = (File)sa;
  9. File f2 = (File)sb;
  10. if (f1.getName().charAt(0) < f2.getName().charAt(0)) {
  11. return 1;
  12. } else {
  13. return 0;
  14. }
  15. });
  16. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.