 <p>The easiest way to do it directly in the list is</p> <pre><code>HashSet&lt;Object&gt; seen=new HashSet&lt;&gt;(); employee.removeIf(e-&gt;!seen.add(e.getID())); </code></pre> <ul> <li><code>removeIf</code> will remove an element if it meets the specified criteria</li> <li><code>Set.add</code> will return <code>false</code> if it did not modify the <code>Set</code>, i.e. already contains the value</li> <li>combining these two, it will remove all elements (employees) whose id has been encountered before</li> </ul> <p>Of course, it only works if the list supports removal of elements.</p>