java - ArrayList sorting by file.length() -
java - ArrayList<File> sorting by file.length() -
this question has reply here:
comparator won't work arrays.sort 5 answersi want sort arraylist
size of file
s contained in it.
public class arraysorting implements comparator<file> { public arraysorting() { } public arraylist<file> sort(arraylist<file> arrayoffiles) { arrays.sort(arrayoffiles, new arraysorting()); homecoming arrayoffiles; } public int compare( file a, file b ) { long asize = a.length(); long bsize = b.length(); if ( asize < bsize ) { homecoming -1; } else if (asize > bsize) { homecoming 1; } else { homecoming 0; } } }
i got error:
the method sort(t[], comparator) in type arrays not applicable arguments (arraylist, arraysorting).
arrays.sort
expects array. utilize collections.sort
in order sort list
.
public arraylist<file> sort(arraylist<file> arrayoffiles) { collections.sort(arrayoffiles, new arraysorting()); homecoming arrayoffiles; }
java sorting arraylist
Comments
Post a Comment