Java List Remove Duplicate removeRepeat(List list)

Here you can find the source of removeRepeat(List list)

Description

remove Repeat

License

Open Source License

Declaration

public static <T> List<T> removeRepeat(List<T> list) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    public static <T> List<T> removeRepeat(List<T> list) throws Exception {
        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);/*from  w w  w.jav a  2  s  . com*/
        }
        try {
            list.clear();
            list.addAll(map.values());
        } catch (Exception e) {
        }
        return new ArrayList<T>(map.values());
    }
}

Related

  1. removeDuplicates(List lst)
  2. removeDuplicateWithOrder(List list)
  3. removeDups(List in)
  4. removeEqualItems(List list)
  5. removeRepeat(List list)
  6. renameDuplicateStrings(List strNames)