title: Code Refactoring, How to Avoid double for loops
body: <p>I am using two loops to create an image object which contains the path to the image in the file system
  I could not avoid using two for loops to do this task.
  Can I do the same thing using one for loop?</p>
  <pre><code>   List&lt;String&gt; filesInFolder = null;
         List&lt;Image&gt; images = new ArrayList&lt;Image&gt;();
         try {
             filesInFolder = Files.walk(Paths.get(path)).filter(Files::isRegularFile).map(Path::toString)
                     .collect(Collectors.toList());
         } catch (IOException e) {
             e.printStackTrace();
         }
  
         for (int i = 0; i &lt; filesInFolder.size(); i++) {
             images.add(new Image(filesInFolder.get(i)));
         }
  </code></pre>