title: Is it possible to store files of a folder in dynamic array in Java
body: <p>I am trying to find same name files in two folders.
  I used File and listed names of file in two array list.
  then i added common name files in two folders to a new arraylist and going to apply diff to find if these files are different or not.</p>
  
  <p>As i have only stored name of files in Array List, i can't apply operation on those files directly.</p>
  
  <p>Someone told me that by the use of dynamic array one can save files in Java... </p>
  
  <p>My code till now with help of some great friends :</p>
  
  <pre><code>import java.io.File;
  import java.util.*;
  
  public class ListFiles1 
  {
  
      public static void main(String[] args) 
      {
  
          String path1 = "C:\\Users\\hi\\Downloads\\IIT Typing\\IIT Typing"; 
  
          String path2 = "C:\\Users\\hi\\Downloads\\IIT Typing\\IIT Typing"; 
  
          File folder1 = new File(path1);
          File folder2 = new File(path2);
  
          String[] f1=folder1.list();
  
          File[] listOfFiles1 = folder1.listFiles(); 
          File[] listOfFiles2 = folder2.listFiles(); 
  
          ArrayList&lt;String&gt; fileNames1 = new ArrayList&lt;&gt;();
          ArrayList&lt;String&gt; fileNames2 = new ArrayList&lt;&gt;();
  
          for (int i = 0; i &lt; listOfFiles1.length; i++) 
          {
  
              if (listOfFiles1[i].isFile()) 
              {
                  fileNames1.add(listOfFiles1[i].getName());
                 // System.out.println(f1[i] + " is a file");
              }
  
          }
  
          for (int j = 0; j &lt; listOfFiles2.length; j++) 
          {
  
              if (listOfFiles2[j].isFile()) 
              {
                  fileNames2.add(listOfFiles2[j].getName());
              }
          }
  
      ArrayList&lt;String&gt; commonfiles = new ArrayList&lt;&gt;();
      for (int i = 0; i &lt; listOfFiles1.length; i++)
      {
          for (int j = 0; i &lt; listOfFiles2.length; j++) 
              {
              String tempfilename1;
              String tempfilename2;
              tempfilename1=fileNames1.get(i);
              tempfilename2 = fileNames2.get(j);
              if(tempfilename1.equals(tempfilename2))
                  {
                  commonfiles.add(tempfilename1);
                  System.out.println(commonfiles);
                  }
              }
      }            
  
      }
  }
  </code></pre>