title: Using apache FTPclient to sort and download files using Collections.sort()
body: <p>I am using the apache FTPClient to download files from an FTP site using the following libraries</p>
  
  <pre><code>import org.apache.commons.net.ftp.FTPClient;
  import org.apache.commons.net.ftp.FTPConnectionClosedException;
  import org.apache.commons.net.ftp.FTPFile;
  import org.apache.commons.net.ftp.FTPFileFilter;
  </code></pre>
  
  <p>The files in the FTP folder are in the following format </p>
  
  <pre><code>NNNN_YYYYMMDDHHMMSS.SSS
  </code></pre>
  
  <p>Examples are provided below:</p>
  
  <pre><code>32345_20131224091824445.zip
  42345_20131224091824545.zip
  12345_20131224091824145.zip
  22345_20131224091824345.zip
  52345_20131224091824745.zip
  62345_20131224091824645.zip
  </code></pre>
  
  <p>What i do at the moment is i list the files in the directory using the listDir() method and add each filename into an ArrayList. </p>
  
  <p>I then sort the ArrayList using Collections.sort(myArrayOfFileNames). This has has far worked for me as it sorts the files by the filenames. </p>
  
  <p>Now i want to sort the files by the timestamp on the filename (not system timestamp). This means i have to somehow strip out everything before and including the _ character before doing the sort. </p>
  
  <p>Given that i need the complete filename to be able to download the file after the sort, i am thinking i should have some kind of key, value map where i would store the full name as the key and the stripped out value as the 'value' in the map then sort the values. My map would look something like this</p>
  
  <pre><code>key                         value
  32345_20131224091824445.zip 20131224091824445.zip
  42345_20131224091824545.zip 20131224091824545.zip
  12345_20131224091824145.zip 20131224091824145.zip
  22345_20131224091824345.zip 20131224091824345.zip
  52345_20131224091824745.zip 20131224091824745.zip
  62345_20131224091824645.zip 20131224091824645.zip
  </code></pre>
  
  <p>The above solution would probably work but is there a quicker or cleaner solution because i feel the above solution is probably not the best. </p>