java - Fast sort by date of huge file ArrayList -


I have an Arrayist in Java that contains a large amount of files (~ 40.000 files) I get these files mounted from their date Need descending / descending. At present, I use a simple

  collection. File (filelist, new filet compactor ());  

Where the file is compactor

  Public class FileDateComparator Comparator & lt; File & gt; {@ Compare Override Public Ent (File O1, File O2) {If (OASSMM) (Lieutenant); O2. Alistead ()) Return -1; If (o1.lastModified () == o2.lastModified ()) 0; Return 1; }}  

It takes a lot of time for me, like 20 seconds or more, is there a more efficient way to realize this? I have already used the Apache I / O final modified file compiler as a comparator, but it seems that in the same way, because it takes only one time.

I think you have to cache the time of amendment to increase this speed. Try doing something like this for example:

  class dated file {file; f; Longer moded; Public datefile (filef, long moddate) {this.f = f; This.moddate = moddate; }}; ArrayList & LT; DatedFile & gt; Dated Files = New Arrestist & lt; DateFile & gt; (); (File f: filelist) for {dated files. (New dated file (F, F. Alisted ())); } Collections.sort (filelist, new filet compactor ()); ArrayList & LT; File & gt; Sort file = new arreelist & lt; File & gt; (); For (datefilef: dated files) {sortedFiles.add (f.f); }  

(with an appropriate FileDateComparator implementation)


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -