private List<T> deWeight(List<T> list, String type){
if (CollectionUtils.isEmpty(list))
return null;
while (StringUtils.isNotBlank(type)) {
switch (type) {
case "1":
for (int i = 0; i < list.size(); i++) {
for (int j = i + 1; j < list.size(); j++) {
if (list.get(i).equals(list.get(j))) {
list.remove(j);
}
}
}
case "2":
List<T> newList = new ArrayList<>();
for (T obj : list) {
if (!newList.contains(obj)) {
newList.add(obj);
}
}
list.clear();
list.addAll(newList);
case "3":
HashSet hashSet = new HashSet(list);
list.clear();
list.addAll(hashSet);
case "4":
TreeSet treeSet = new TreeSet(list);
list.clear();
list.addAll(treeSet);
case "5":
list.stream().distinct().collect(Collectors.toList());
case "7":
//快慢指针的形式,集合中的数据得是有顺序的,否则去重会有问题慎用
int slowIndex = 0;
for (int fastIndex = 1; fastIndex < list.size(); fastIndex++) {
if (list.get(slowIndex) != list.get(fastIndex)) {
slowIndex ++;
list.set(slowIndex, list.get(fastIndex));
}
}
list.subList(0,slowIndex);
default:
list = list;
}
}
return list;
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。