title: Selecting a range of files in a directory, Java
body: <p>I have a function which lists files under a given path</p>
  
  <pre><code>public static String[] listFiles(String path)
  </code></pre>
  
  <p>the files are named course_1 -to- course_15.</p>
  
  <p>I want to implement some functionality which allows me to only select files in a given range:</p>
  
  <pre><code>public static String[] listFiles(String path, int startIndex, int endIndex)
  </code></pre>
  
  <p>where the int's passed as arguments correspond to the 1 - 15.</p>
  
  <p>eg.</p>
  
  <p>if the startIndex = 9, and the endIndex = 11, then only select:</p>
  
  <p>course_9
  course_10
  course_11</p>
  
  <p>Is there any way to implement this whihout making the function relatively complex? Also there are no file extensions used.</p>
  
  <p><strong>Edit:</strong>
  I should also mention that the path is the root directory of where the files exist:</p>
  
  <pre><code>for(String content:localDirectory.list()){
      if(content!=null){
          File contentFile= new File(path + "/" + content);                   
  
          if(!contentFile.isDirectory()){
              files.add(contentFile.getAbsolutePath());
          }
      }
  }
  
  if (files.size()==0)
      return null;
  } else{ 
      return files.toArray(new String[files.size()]);
  
  }
  </code></pre>
  
  <p>where files is an ArrayList initalised inside the method</p>