title: How to find similar lines in two text files irrespective of the line number at which they occur
body: <p>I am trying to open two text files and find similar lines in them.
  My code is correctly reading all the lines from both the text files.
  I have used nested <code>for</code> loops to compare <code>line1</code> of first text file with all lines of second text file and so on.
  However, it is only detecting similar lines which have same line number,
  (eg. line 1 of <code>txt1</code> is <code>cc cc cc</code> and line 1 of <code>txt2</code> is <code>cc cc cc</code>, then it correctly finds and prints it),
  but it doesn't detect same lines on different line numbers in those files.</p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  
  public class FeatureSelection500 {
  
      public static void main(String[] args) throws FileNotFoundException, IOException {
          // TODO code application logic here
  
          File f1 = new File("E://implementation1/practise/ComUpdatusPS.exe.hex-04-ngrams-Freq.txt");
          File f2 = new File("E://implementation1/practise/top-300features.txt");
  
          Scanner scan1 = new Scanner(f1);
  
          Scanner scan2 = new Scanner(f2);
  
          int i = 1;
          List&lt;String&gt; txtFileOne = new ArrayList&lt;String&gt;();
  
          List&lt;String&gt; txtFileTwo = new ArrayList&lt;String&gt;();
  
          while (scan1.hasNext()) {
              txtFileOne.add(scan1.nextLine());
          }
  
          while (scan2.hasNext())
  
          {
  
              txtFileTwo.add(scan2.nextLine());
          }
       /*
      for(String ot : txtFileTwo )
      {
      for (String outPut : txtFileOne)
  
      {
         // if (txtFileTwo.contains(outPut))
          if(outPut.equals(ot))
          {
  
             System.out.print(i + " "); 
  
             System.out.println(outPut);
             i++;
  
  
          }
  
      }
      }
  */
  
          for (int j = 0; j &lt; txtFileTwo.size(); j++) {
  
              String fsl = txtFileTwo.get(j);
              //  System.out.println(fileContentSingleLine);
  
              for (int z = 0; z &lt; 600; z++)                                 // z &lt; txtFileOne.size()
              {
                  String s = txtFileOne.get(z);
                  //  System.out.println(fsl+"\t \t"+ s);
                  if (fsl.equals(s)) {
                      System.out.println(fsl + "\t \t" + s);
                      // my line
  
                      // System.out.println(fsl);
                  } else {
                      continue;
                  }
              }
          }
      }
  }
  </code></pre>