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 answers

i want sort arraylist size of files 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

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -