title: How I do compare objects in a ArrayList against each other in Java
body: <p>I have two entities:<br> <code>Individual</code> and <code>TaxPayer</code> in the following way: <br></p>
  <pre><code>public class Individual {     
     private String firstName;
     private String lastName;
     @OneToOne
     private TaxPayer taxpayer;
     // other fields
  }
  </code></pre>
  <p>and:<br></p>
  <pre><code>public class TaxPayer {
     private String phoneNumber;
     private String stateTin;//unique code
     private String email;
     //other fields
  }
  </code></pre>
  <p>I have a list of individuals like so:</p>
  <pre><code>List&lt;Individual&gt; individualList = getAllIndividualsWithDuplicatePhonenumber();
  </code></pre>
  <p>I want to compare the firstName and lastName of an individual with other individuals in the list so that I will get a list of all individuals where the <strong>firstName and lastName matches with the other individual's firstName and lastName</strong> OR <strong>firstName of the individual matches the lastName of the other individual and lastName of the individual matches the firstName of the other individual</strong>
  PS: TaxPayer entity is eager-fetched on Individual so I can access the attributes of TaxPayer by doing <code>individual.getTaxPayer().getPhoneNumber();</code></p>