Java List Remove Duplicate removeDuplicates(List lst)

Here you can find the source of removeDuplicates(List lst)

Description

remove Duplicates

License

Open Source License

Declaration

public static <V> void removeDuplicates(List<V> lst) 

Method Source Code


//package com.java2s;

import java.util.*;

public class Main {
    public static <V> void removeDuplicates(List<V> lst) {
        for (ListIterator<V> it = lst.listIterator(); it.hasNext();) {
            int idx = it.nextIndex();
            V elem = it.next();//from   w  w  w.j  ava2  s  .co m
            if (idx < lst.size() - 1 && lst.subList(idx + 1, lst.size() - 1).contains(elem))
                it.remove();
        }
    }

    /**
     * Create a sub list with just these indices
     */
    public static <T1> List<T1> subList(List<T1> lst, Collection<Integer> indices) {
        List<T1> sublst = new ArrayList<>();
        for (Integer idx : indices)
            sublst.add(lst.get(idx));
        return sublst;
    }
}

Related

  1. removeDuplicates(List commonVars)
  2. removeDuplicates(List l)
  3. removeDuplicates(List collection)
  4. removeDuplicates(List list)
  5. removeDuplicates(List list, Comparator comparator)
  6. removeDuplicateWithOrder(List list)
  7. removeDups(List in)
  8. removeEqualItems(List list)
  9. removeRepeat(List list)