Java Utililty Methods List Remove Duplicate

List of utility methods to do List Remove Duplicate

Description

The list of methods to do List Remove Duplicate are organized into topic(s).

Method

ListremoveDuplicates(List collection)
remove Duplicates
List<T> list = new ArrayList<T>();
for (T item : collection)
    if (!list.contains(item))
        list.add(item);
return list;
ListremoveDuplicates(List list)
Remove all duplicate objects from a list
Set<T> s = new HashSet<>();
for (Iterator<T> iter = list.iterator(); iter.hasNext();) {
    T element = (T) iter.next();
    if (!s.add(element)) {
        iter.remove();
return list;
...
voidremoveDuplicates(List list, Comparator comparator)
Sorts and removes duplicate elements from list .
Collections.sort(list, comparator);
int j = 1;
for (int i = 1; i < list.size(); i++) {
    if (comparator.compare(list.get(j - 1), list.get(i)) != 0) {
        T object = list.get(i);
        list.set(j++, object);
if (j < list.size()) {
    list.subList(j, list.size()).clear();
voidremoveDuplicates(List lst)
remove Duplicates
for (ListIterator<V> it = lst.listIterator(); it.hasNext();) {
    int idx = it.nextIndex();
    V elem = it.next();
    if (idx < lst.size() - 1 && lst.subList(idx + 1, lst.size() - 1).contains(elem))
        it.remove();
voidremoveDuplicateWithOrder(List list)
remove Duplicate With Order
Set<String> set = new HashSet<String>();
List<String> newList = new ArrayList<String>();
for (Iterator<String> iter = list.iterator(); iter.hasNext();) {
    String element = iter.next();
    if (set.add(element))
        newList.add(element);
list.clear();
...
ListremoveDups(List in)
remove Dups
Set<T> set = new LinkedHashSet<T>();
set.addAll(in);
if (set.size() == in.size())
    return in;
List<T> result = new ArrayList<T>();
for (T t : set)
    result.add(t);
return result;
...
ListremoveEqualItems(List list)
Ontdubbeld de items van deze lijst.
if (list == null || list.isEmpty())
    return list;
T temp = null;
List<T> sublist;
for (int i = 0; i < list.size() - 1; i++) {
    temp = list.get(i);
    sublist = list.subList(i + 1, list.size());
    while (sublist.remove(temp)) {
...
ListremoveRepeat(List list)
remove Repeat
if (isEmpty(list)) {
    return list;
List<T> result = new ArrayList<T>();
for (T e : list) {
    if (!result.contains(e)) {
        result.add(e);
return result;
ListremoveRepeat(List list)
remove Repeat
Map<Integer, T> map = new HashMap<Integer, T>();
if (list == null)
    return null;
for (T t : list) {
    if (t == null)
        continue;
    map.put(t.hashCode(), t);
try {
    list.clear();
    list.addAll(map.values());
} catch (Exception e) {
return new ArrayList<T>(map.values());
ListrenameDuplicateStrings(List strNames)
rename Duplicate Strings
if (strNames == null) {
    return null;
HashMap<String, Integer> seenBefore = new HashMap<String, Integer>(4);
List<String> results = new ArrayList<String>(strNames.size());
for (String str : strNames) {
    Integer lookup = seenBefore.get(str);
    if (lookup == null) {
...