title: Compare two tables in Java
body: <p>I have to compare two tables and tell the user what's the difference between two tables.</p>
  
  <p>Table1 </p>
  
  <pre><code>------+---------
  |Code | Label   |  
  ------+---------  
  |a1   | a1text  |  
  ------+---------  
  |b1   | b1text  |  
  ------+---------  
  |c1   | bartext1|  
  ------+---------  
  |e1   | foo     |  
  -----+--------- 
  </code></pre>
  
  <p>Table2  </p>
  
  <pre><code>------+---------  
  |Code | Label   |  
  ------+---------  
  |a1   | a1text  |  
  ------+---------  
  |b1   | b2text  |  
  ------+---------  
  |d1   | bartext2|  
  ------+---------  
  |f1   | bar     |  
  ------+--------- 
  </code></pre>
  
  <p><b>Comparison Info</b><br>
  As you see in table1 for Code <code>c1</code> label is <code>bartext1</code> and for Code <code>d1</code> label is <code>bartext2</code>.
  They are same expect last character. I have to put in my report they are same except last character. There are few rows in tables where there may be extra word or special character and its position is anywhere. Somehow I have to tell in the report both labels are same expect word is missing or there is a special character in one of them.Code is not important in report.</p>
  
  <p><b>More Info</b><br>
    This data is coming from Third party.Code is always unique, they are no duplicate Codes.
  It may be possible that two codes have similar value 
  like </p>
  
  <p>Code | Label      </p>
  
  <p>ER4 |     i have a brother</p>
  
  <p>WE3  |    i have a brother</p>
  
  <p><b>Expected Output should be</b>  </p>
  
  <ol>
  <li>Labels are different in two tables. Table1 label is : b1text  and Tabl2 label is: b2text. </li>
  
  <li>Labels are different in two tables. Table1 label is : bartext1  and Tabl2 label is: bartext2.</li>
  <li>label foo is missing in Table2.</li>
  <li>label bar is missing in Table1.</li>
  </ol>