title: Best way to list files in Java, sorted by Date Modified?
body: <p>I want to get a list of files in a directory, but I want to sort it such that the oldest files are first.  My solution was to call File.listFiles and just resort the list based on File.lastModified, but I was wondering if there was a better way.</p>
  
  <p>Edit: My current solution, as suggested, is to use an anonymous Comparator:</p>
  
  <pre><code>File[] files = directory.listFiles();
  
  Arrays.sort(files, new Comparator&lt;File&gt;(){
      public int compare(File f1, File f2)
      {
          return Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
      } });
  </code></pre>