Possible Duplicate:
Java: Detect duplicates in ArrayList?
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.
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??
For iteration purposes the JSP requires I throw the list of hotParts
into an additional ArrayList
This is the code..there is more to it, but this is the part that matters
Thanks
try
{
List<Object> dataList = new ArrayList<Object>();
Set<Long> ids = new HashSet<Long>();
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!!!!!!! :)