compare two Lists of objects and return a list which has common objects in two
<p>I have two lists -</p>

<pre><code>ArrayList&lt;MyObject&gt; list1 -&gt; [obj1, obj2, obj3, obj4, obj5, obj6]

ArrayList&lt;MyObject&gt;  list2 -&gt; [obj1, obj6, obj7, obj8]
</code></pre>

<p>Is there any utility method already existing in java api which can give a list of only common records of two?</p>

<p>expected list ->
<code>[obj1, obj6]</code></p>

<p>MyObject looks like this -</p>

<pre><code>class MyObject {
  public Integer number;
  public String name;
  public Integer parent;
  public String parentName;
}
</code></pre>

<p>I only need to use <code>number</code> and <code>name</code> to do the comparison.</p>

<hr>

<p>i am aware of approach using <code>retainAll</code> or <code>removeAll</code> to get the desired list. The problem however is, <strong>I cannot override <code>equals</code> method of <code>MyObject</code> as it is used for some different purpose</strong>. And the <code>retainAll</code> or <code>removeAll</code> method doesn't seems to accept <code>Comparator</code> object.</p>

<p>I know another solution is to iterate through the lists and find the common ones. I am looking if there is already some method which do it.</p>

<p>Thanks.</p>
