title: In what order does java sort through files/directories?
body: <p>I am somewhat new to java and am trying to create a program which loops through and prints out all of the directories that are inside of a specified location. Here is what I have so far:</p>
  
  <pre><code>import java.io.File;
  
  
  public class main{
  
      public static void main(String[] args) {
          File[] files = new File("/media/will/External/Movies").listFiles();
          showFiles(files);
      }
  
      public static void showFiles(File[] files) {
          String name;
          for (File file : files) {
              if (file.isDirectory()) {
                  name = file.getName();
                  if (!(name.contains("!")) &amp;&amp; name.contains("(") &amp;&amp; name.contains(")")) {
                      System.out.println("Directory: " + name);
                  }
                  showFiles(file.listFiles()); // Calls same method again.
              } else {
                  // System.out.println("File: " + file.getName());
  
              }
          }
      }
  }
  </code></pre>
  
  <p>As you can see, I have some checks in there to only print out certain folder names (has to include both "(" and ")" and can't include "!"). </p>
  
  <p>A segment of output that I get in the console is this:</p>
  
  <pre><code>Directory: The Matrix (1999)
  Directory: The Matrix Reloaded (2003)
  Directory: The Matrix Revolutions (2003)
  Directory: American Pie 1 (1999)
  Directory: American Pie 2 (2001)
  Directory: American Pie 3 - The Wedding (2003)
  Directory: American Pie 4 - Band Camp (2005)
  Directory: American Pie 5 - The Naked Mile (2006)
  Directory: American Pie 6 - Beta House (2007)
  Directory: American Pie 7 - The Book of Love (2009)
  Directory: American Pie 8 - Hole In One (2010)
  Directory: Borat (2006)
  Directory: Casino Royale (2006)
  Directory: Despicable Me 2 (2013)
  Directory: Elysium (2013)
  Directory: Horrible Bosses (2011)
  Directory: Finding Nemo (2003)
  Directory: Friday Night Lights (2004)
  Directory: Full Metal Jacket (1987)
  Directory: Gladiator (2000)
  Directory: Hannibal (2001)
  Directory: Nightcrawler (2014)
  Directory: How To Train Your Dragon (2010)
  Directory: I Am Legend (2007)
  </code></pre>
  
  <p>From what I can tell, there is no right or reason to the current order that I am I getting the directories returned in. For some parts it seems to be alphabetical, but for other areas it seems to be random.</p>
  
  <p>The end goal is for the output to be alphabetical, however I want to understand why this order is present first.</p>
  
  <p>Thanks!!</p>