Java Duplicates in Arraylist
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/562894/java-detect-duplicates-in-arraylist">Java: Detect duplicates in ArrayList?</a>  </p>
</blockquote>



<p>I have a strange issue.  Im sending out email alerts when remarks get added to a form.  Basically each remarks has its own individual id, but multiple remarks can attached to certain form.</p>

<p>In this scenario I have 3 remarks that I added.  Two were added to 1 form and the last to a different form. So I would like it just to send 2 forms.  The email is sending out 3 forms.  I understand that 3 beans will get populated, but 2 will have the same data because 2 remarks belong to the same form.  I tried some algorithms I seen posted on here for dups in and what not, but I guess the code is not recognizing duplicate elements because the remarks each have their own id??</p>

<p>For iteration purposes the JSP requires I throw the list of <code>hotParts</code> into an additional <code>ArrayList</code></p>

<p>This is the code..there is more to it, but this is the part that matters</p>

<p>Thanks</p>

<pre><code>   try
                    {
                        List&lt;Object&gt; dataList = new ArrayList&lt;Object&gt;();
                        Set&lt;Long&gt; ids = new HashSet&lt;Long&gt;();

                        for (HotPartsRemarkBean remark : latestHotPartRemarks)
                        {
                            ids.add(remark.getHpId());  
                        }

                            for ( Long id : ids)
                            {
                                hotPart = hotPartsDAO.getHotPartById(id);
                                dataList.add( hotPart ); //List Of Hot Parts Beans
                            }


               THIS WORKS!!!!!!! :)
</code></pre>
