title: Value inserted into a Map does not remain there in the second loop of a cycle
body: <p>The funciton below copies all files with given extension from rootDirectory into given destination. It works well when names of the files differ, however when there are two files with the same name (see the recurvive call - it can be in the subdirectory), it does not do what it should. If there are more files with the same name, it should copy both and rename the second (adding _1, _2,... to its name). </p>
  
  <p>I see there might be a problem with the Map I am using - every time a file is copied, I want to save it's name and add counter that counts how many times it has been copied (so the appropriate number can be added to its name). Could you please help me to fix the problem? </p>
  
  <pre><code>void copy(File rootDirectory, String destination, String fileExtension) {
      File destFile = new File(destination);
      HashMap&lt;String, Integer&gt; counter = new HashMap&lt;&gt;();
      for (File file : rootDirectory.listFiles()) {
          try {
              if (file.isDirectory()) { copy(file, destination, fileExtension);
              } else if (getExtension(file.getPath().toLowerCase()).equals(fileExtension.toLowerCase())) { 
                  if (!destFile.exists()) { destFile.mkdirs();}
                  String fileName = file.getName();
                  if(counter.containsKey(fileName)){  // &lt;&lt;-- IS NEVER TRUE 
                      int count = counter.get(fileName);
                      count++;
                      counter.put(fileName, count);
                      int i = fileName.contains(".") ? fileName.lastIndexOf('.') : fileName.length();
                      fileName = fileName.substring(0, i) + "_" + count + fileName.substring(i);
                  } else{ counter.put(fileName, 0);
                  }
                  Files.copy(file.toPath(), Paths.get(destination + "\\" + fileName), StandardCopyOption.REPLACE_EXISTING);
              }
          } catch (IOException e) {
              //...
          }
      }
  } 
  </code></pre>