Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.Set; public class Main { public static final Collection getDistinctCollection(Collection collection) { Collection distinct = collection != null ? new ArrayList(collection) : collection; distinctCollection(distinct); return distinct; } public static final void distinctCollection(Collection<? extends Object> collection) { if (collection != null && !collection.isEmpty()) { Set<? extends Object> distinctSet = new HashSet<Object>(collection); collection.clear(); ((Collection<Object>) collection).addAll(distinctSet); } } public static boolean isEmpty(Collection<?> collection) { return collection == null || collection.isEmpty(); } }