C# 控制list对象删除重复记录
转自:http://blog.csdn.net/learner9023/article/details/8434528
两种比较实用的方法,一个是双循环,一个是hashset.
一.循环
public static List removeDuplicate(List list) { for ( int i = 0 ; i < list.size() - 1 ; i ++ ) { for ( int j = list.size() - 1 ; j > i; j -- ) { if (list.get(j).equals(list.get(i))) { list.remove(j); } } } return list; }
二.hastset
public static List removeDuplicate(List list) { HashSet h = new HashSet(list); list.clear(); list.addAll(h); return list; }