Blogger

Delete comment from: Javarevisited

Anonymous said...

@Avinash, to remove duplicates from the list w/o using another list, use an iterator and a temporary set.
Set seen = HashSet();
Iterator it = myObject.iterator();
while (it.hasNext()) {
final MyObject o = it.getNext();
if (seen.contains(o)) {
it.remove(o);
} else {
seen.add(o);
}
}

Jan 6, 2015, 3:02:01 AM


Posted to How to remove duplicates elements from ArrayList in Java - Example

Google apps
Main menu