Here are two ways to help you delete Elements in an ArrayList. In the following program clip, the RemoveDuplicate method does not maintain the order (ORDER), and the REMOVEDUPLICATEWITHERDER method holds the order (ORDER), but there will be some performance sacrifices.
The RemoveDuPlicate Method:
/ ** list ORDER NOT MAINTAINED ** /
Public Static Void RemoveDuPlicate (ArrayList Arlliist)
{
Hashset h = new hashset (arllist);
arllist.clear ();
arllist.addall (h);
}
The RemoveDuplicateWithOrder method:
/ ** list ORDER MainTained ** /
Public Static Void RemoveduplicateWithOrder (arraylist arllist)
{
SET set = new hashset ();
List newlist = new arraylist ();
ITerator it = arllist.iterator (); it.hasnext ();) {
Object element = iter.next ();
IF (SET.ADD (ELEMENT))
Newlist.add (element);
}
arllist.clear ();
arllist.addall (newlist);
}