list 去重并保持原来排序

public  <T> List<T> removeDuplicateKeepOrder(List<T> list){
/* Set set = new HashSet();
List<T> newList = new ArrayList<T>();
for (T element : list) {
if (set.add(element)) newList.add(element);
}
//list.clear();
//list.addAll(newList);
//return list;
  return newList;*/
return  new ArrayList<T>(new LinkedHashSet<T>(list));
}
posted on 2018-09-18 20:57  风景1573  阅读(464)  评论(4编辑  收藏  举报