title: Compare two Files and determine which lines are different
body: <p>I'm working on a project where I need to read in two files, and then compare them in order to find how many lines are different. For example, if I had two files:
  1.Cat
  2.Dog
  3.Shark
  4.Penguin
      and
  1.Cat
  2.Dog
  3.Penguin
  4.Octopus
  The end result would say, "These files are not the same, there are two differences."
  Here is my coding so far: I have read the files in and stored each line of the file in a new part of the list. Now I am just looking for a way to compare them properly in order to find there differences. The way i am comparing them now does not account for order :/ Here is my code:</p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  
  public class myfilereader
  {
      public static void main (String[] args) throws java.io.IOException
      {
  
  
          ArrayList&lt;String&gt; ArrayList1 = new ArrayList&lt;String&gt;();
          ArrayList&lt;String&gt; ArrayList2 = new ArrayList&lt;String&gt;();
          ArrayList&lt;String&gt; ArrayList3 = new ArrayList&lt;String&gt;();
          try
          {
              Scanner File1 = new Scanner(new File("/Users/Home/Desktop/File1.txt"));
              while (File1.hasNext())
              {
                  ArrayList1.add(File1.next());
              }
  
              Scanner File2 = new Scanner(new File("/Users/Home/Desktop/File2.txt"));
              while (File2.hasNextLine())
              {
                  ArrayList2.add(File2.next());
              }
          }
          catch (FileNotFoundException ex)
          {
              ex.printStackTrace();
          }
          for (String ArrayList : ArrayList1) 
          {
              System.out.println("File 1: " + ArrayList1);
          }
          for (String ArrayList : ArrayList2) 
          {
              System.out.println("File 2: " + ArrayList2);
          }
          ArrayList1.removeAll(ArrayList2);
          System.out.println(ArrayList1);
  
  
      }
  }
  </code></pre>