Removes any duplicates in a collection, while preserving the order if it is an ordered collection. Efficient enough for most cases.
public static > T removeDuplicates(T collection)
{
Set setItems = new LinkedHashSet(collection);
collection.clear();
collection.addAll(setItems);
return collection;
}